问题
I have written my webpack.config file but when i run webpack from terminal i get back an error saying:
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.
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"
}
}
回答1:
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']
}
}
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.
来源:https://stackoverflow.com/questions/47432600/webpack-command-in-node-brings-config-webpack-development-js-not-found