首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webpack和角度错误无法读取属性“”setGlobalVar“”

Webpack和角度错误无法读取属性“”setGlobalVar“”
EN

Stack Overflow用户
提问于 2017-05-11 03:23:15
回答 1查看 484关注 0票数 1

在运行程序的UI时,开发人员工具显示错误Cannot read property 'setGlobalVar' of null ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'setGlobalVar' of null.

我的webpack.config.js:

代码语言:javascript
复制
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        polyfills: './app/polyfills.ts',
        app: './app/main.ts'
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: '[name].js',
        sourceMapFilename: '[file].map'
    },
    module: {
        rules: [
            //Order of loaders is important!
            {
                test: /\.ts(x?)$/,
                exclude: ['node_modules'],
                use: [{ loader: 'babel-loader' },{ loader: 'ts-loader' }, { loader: 'angular-router-loader' }, { loader: 'angular2-template-loader' }],
            },
            {
                test: /\.sass$/,
                exclude: ['node_modules'],
                use: [{ loader: 'css-to-string-loader' }, { loader: 'raw-loader' }, { loader: 'sass-loader', options: { sourceMap: true, sourceMapContents: true } }]
            },
            {
                test: /\.css$/,
                exclude: ['node_modules'],
                use: [{ loader: 'css-to-string-loader' }, { loader: 'raw-loader' }, { loader: 'css-loader' }]
            },
            {
                test: /\.html$/,
                exclude: ['node_modules', 'index.html'],
                use: [{ loader: 'raw-loader' }]
            },
            {
                test: /\.(otf|eot|svg|png|ttf|woff|woff2).*$/,
                exclude: ['node_modules'],
                use: [{ loader: 'url-loader' }]
            }
        ]
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js', '.css'],
        modules: ["node_modules", "."]
    },
    plugins: [

      new webpack.optimize.CommonsChunkPlugin({
          names: ['vendor'],
          minChunks: function (module, count) {
              // creates a common vendor js file for libraries in node_modules
              return module.context && module.context.indexOf('node_modules') !== -1;
          }
      }),

      new webpack.optimize.CommonsChunkPlugin({
          names: ['meta'],
          chunks: ['vendor', 'app']
      }),

      new HtmlWebpackPlugin({
          template: 'index.cshtml',
          filename: 'index.cshtml',
          inject: 'head'
          , chunks: ['app', 'vendor', 'polyfills', 'meta']
          , chunksSortMode: 'dependency'
          , hash: false
      }),

      new webpack.ContextReplacementPlugin(
        /angular(\\|\/)core(\\|\/)@angular/, //Update for Angular 4
        root('./app'),
        {}
      ),
    ]
};
function root(__path) {
    return path.join(__dirname, __path);
}

我使用的是Angular 4.1.0,这个问题错误是在从Angular 2更新到Angular 4之后才出现的。在谷歌搜索中对这个问题的支持非常少,所以任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2017-06-01 12:16:13

信不信由你,这个问题和你的Webpack配置无关。

要纠正该错误,请在环境配置文件(通常是environment.ts文件)中注释或删除disableDebugTools()调用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43901123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档