节点中的Webpack命令导致未找到/config/webpack/development.js [英] Webpack command in node brings /config/webpack/development.js not found

查看:390
本文介绍了节点中的Webpack命令导致未找到/config/webpack/development.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了webpack.config文件,但是当我从终端运行webpack时,我得到一条错误消息:

I have written my webpack.config file but when i run webpack from terminal i get back an error saying:

错误: Webpack配置 找不到/home/likono/learn/yak-yik/config/webpack/development.js, 请运行"bundle exec rails webpacker:install"以安装webpacker 使用默认配置或为您的自定义添加缺少的配置文件 环境.

ERROR: Webpack config /home/likono/learn/yak-yik/config/webpack/development.js not found, please run 'bundle exec rails webpacker:install' to install webpacker with default configs or add the missing config file for your custom environment.

我还全局安装了webpack. 这是我的webpack.config.js

I have also installed webpack globally. Here is my webpack.config.js

var webpack = require("webpack");
var path = require("path");

module.exports = {
    entry: {
        app: './src/app.js'
    },
    output: {
        filename: 'public/build/bundle.js',
        sourceMapFilename: 'public/build/bundle.map'
    },
    devtool: '#source-map',
    module: {
        loaders: [
            {   test: /\.jsx?$/,
                exclude: /(node_modules)/,
                loader: 'babel',
                query: {
                    presets: ['react', 'es2015']
                }
            }
        ]
    }
};

package.json

{
  "name": "yak-yik",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.18.2",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "express": "~4.15.5",
    "hjs": "~0.0.6",
    "mongoose": "^4.13.4",
    "morgan": "~1.9.0",
    "nodemon": "^1.12.1",
    "react": "^16.1.1",
    "react-dom": "^16.1.1",
    "serve-favicon": "~2.4.5"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^3.8.1"
  }
}

推荐答案

我发现上述配置存在一些问题.根据 Babel ,它不再使用loaders时允许省略-loader后缀.您需要指定babel-loader而不是babel.同时不建议使用babel-preset-es2015,建议使用babel-preset-env.虽然我无法重现您的错误(我的错误略有不同),但是通过将loaderbabel更改为babel-loader,然后更改了presets,使我的webpack将文件捆绑在了我的身边es2015webpack.config.js中的env,如下所示:

I found a couple of issues with the configuration above. According to Babel, It's no longer allowed to omit the -loader suffix when using loaders. You need to specify babel-loader instead of babel. Also babel-preset-es2015 is deprecated, it is recommended to rather use babel-preset-env. I could not get to reproduce your error though (I got slightly different ones), but got my webpack to bundle the file on my side by altering the loader from babel to babel-loader and, and presets, changed es2015 to env in webpack.config.js like so:

webpack.config.js

{
  test: /\.jsx?$/,
  exclude: /(node_modules)/,
  loader: 'babel-loader',
  query: {
    presets: ['react', 'env']
  }
}

我也将package.json文件更改为使用babel-preset-env而不是"babel-preset-es2015": "^6.24.1".

I also changed the package.json file to use babel-preset-env instead of "babel-preset-es2015": "^6.24.1".

package.js

    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^3.8.1"

请尝试一下,让我知道它是否可以解决您的问题.

Please give this a try and let me know if it solves your problem.

这篇关于节点中的Webpack命令导致未找到/config/webpack/development.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆