NPM包的模块解析错误

时间:2016-07-07 16:06:25

标签: javascript node.js npm

我在构建时利用Webpack收到了一个奇怪的错误。有问题的错误是指我导入的Got's package.json文件。

Module parse failed: .../node_modules/got/package.json Unexpected token (2:8)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:8)

对导致这种情况的原因感到好奇,如果这是在我的结束或结束。

节点版本:v4.2.0

NPM版本:2.14.7

1 个答案:

答案 0 :(得分:0)

问题是您正在导入json,但没有配置适当的加载器。在你的webpack-confing中为你的加载器添加一个json加载器。看起来应该是这样的:

var config = {
  ....
  module: {
    loaders: [
      ...
      {
        test: /\.json/,
        loader: 'json'
      }
    ]
  },
  ....
}