I'm trying to build a simply application using the MEAN stack, and I'm running into an issue with Webpack. When I run "webpack" from the console, I get the following warnings and errors:
我正在尝试使用MEAN堆栈构建一个简单的应用程序,我遇到了Webpack的问题。当我从控制台运行“webpack”时,我收到以下警告和错误:
WARNING in ./~/require_optional/package.json
Module parse failed: C:\Build\myapp\node_modules\require_optional\package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
WARNING in ./~/require_optional/README.md
Module parse failed: C:\Build\myapp\node_modules\require_optional\README.md Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
WARNING in ./~/require_optional/LICENSE
Module parse failed: C:\Build\myapp\node_modules\require_optional\LICENSE Unexpected token (1:40)
You may need an appropriate loader to handle this file type.
ERROR in ./~/constants-browserify/constants.json
Module parse failed: C:\Build\myapp\node_modules\constants-browserify\constants.json Unexpected token (2:12)
You may need an appropriate loader to handle this file type.
So my questions are:
所以我的问题是:
1. Should Webpack even be trying to load files like README.md and LICENSE? Why would it care about those?
1. Webpack是否应该尝试加载README.md和LICENSE等文件?为什么会关心那些?
2. I have a json-loader hooked up and looking for .json files, so why am I still getting warnings and errors about those?
2.我有一个json-loader连接并寻找.json文件,为什么我仍然收到有关这些的警告和错误?
Here's my Webpack config file:
这是我的Webpack配置文件:
webpack.config.js
var config = require('./environment/shared.js')
var debug = config.env !== 'production';
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? 'inline-sourcemap' : null,
entry: './public/js/app.js',
output: {
path: __dirname + '/public/js',
filename: 'bundle.min.js',
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
module: {
loaders: [
{
test: '/\.json/',
loader: 'json',
},
{
test: '/\.node$/',
loader: 'node-loader',
},
],
},
resolve: {
extensions: ['', '.js', '.json', '.node'],
},
};
1 个解决方案
#1
1
question 1: I think there is something like following in your codebase. namely, require a module whose name is in a variable. In this case, webpack don't know exactly which module you are requiring, so it will load all file.
问题1:我认为您的代码库中存在类似的内容。即,需要一个名称在变量中的模块。在这种情况下,webpack并不确切地知道您需要哪个模块,因此它将加载所有文件。
const moduleName = xxx const module = require(moduleName)
const moduleName = xxx const module = require(moduleName)
question 2: you need to add { test: /\.json$/, loader: "json" }
in module/loaders
for loading json file.
问题2:你需要在模块/加载器中添加{test:/\.json$/,loader:“json”}来加载json文件。
#1
1
question 1: I think there is something like following in your codebase. namely, require a module whose name is in a variable. In this case, webpack don't know exactly which module you are requiring, so it will load all file.
问题1:我认为您的代码库中存在类似的内容。即,需要一个名称在变量中的模块。在这种情况下,webpack并不确切地知道您需要哪个模块,因此它将加载所有文件。
const moduleName = xxx const module = require(moduleName)
const moduleName = xxx const module = require(moduleName)
question 2: you need to add { test: /\.json$/, loader: "json" }
in module/loaders
for loading json file.
问题2:你需要在模块/加载器中添加{test:/\.json$/,loader:“json”}来加载json文件。