NPM:Field'浏览器'不包含有效的别名配置

时间:2017-12-08 10:30:02

标签: javascript npm webpack webpack-2

执行此:

var stringA1 = btoa(stringB);

产生此错误。

我现在正在测试这个,所以application.ts就是这个

node .\node_modules\webpack\bin\webpack.js --config scripts/webpack.config.js --display-error-details

webpack文件如下所示:

export class Aureus {

    constructor() {
        alert('1');
    }

}

我收到此错误? const globule = require("globule"); const path = require("path"); const webpack = require("webpack"); const extractTextPlugin = require("extract-text-webpack-plugin"); const config = { }; const configuration = { context: __dirname, entry: { "application": "application.ts", ...globule.find("aureus/**/*.ts", { srcBase: "./scripts" }), , "vendor": [ "bootstrap", "jquery", "angular", "moment", "lodash", "ramda", ], }, output: { path: path.join(__dirname, "../"), filename: "packed.js" }, devtool: "source-map", plugins: [ new webpack.LoaderOptionsPlugin({ debug: true }), new webpack.optimize.CommonsChunkPlugin({ name: "vendor", filename: "vendor.js" }), new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", "window.jQuery": "jquery", "window.jquery": "jquery", }), ], resolve: { alias: { } }, module: { rules: [ { test: /^((?!\.spec\.ts).)*.ts$/, use: [ { loader: "awesome-typescript-loader" } ], exclude: /(node_modules)/ }, ] } }; module.exports = configuration; 位于application.ts (与webpack.config.js相同的目录)

./scripts/application.ts

2 个答案:

答案 0 :(得分:1)

除非您提供实际的resolve规则,否则node_modules中任何内容的导入都将默认查找提供给context的文件夹。

试试这个:

resolve: {    
  modules: [
    /* assuming that one up is where your node_modules sit,
       relative to the currently executing script
    */
    path.join(__dirname, '../node_modules')
  ]
}

此外,请确保您引用entry相对context的{​​{1}},如下所示:

"application": "./application.ts"

而不是

"application": "application.ts"

答案 1 :(得分:0)

也许你需要检查你的 package-lock.json,并假设你的包版本是正确的

当您的软件包版本不正确时,NPM 会出现此错误。

这里有三个提示:

  1. 检查节点版本:node -v
  2. 进入根目录时确保已经安装:nom i
  3. 检查 package.json 文件中的版本。您可能会发现一些问题。

像这样:

"eslint": "^5.16.0",

代替:

"eslint": "^4.4.0",