Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error ReferenceError: window is not defined #74

Open
yankwan opened this issue Nov 17, 2017 · 2 comments
Open

Error ReferenceError: window is not defined #74

yankwan opened this issue Nov 17, 2017 · 2 comments

Comments

@yankwan
Copy link

yankwan commented Nov 17, 2017

When I run npm run server to start the webpack dev server, it report the error such as below:

Error: E:\js-test\Angularjs-ES6-Demo\src\script\index.html:76
  window.angular.module('ng').run(['$templateCache', function(c) { c.put(path, h  tml) }]);
  ^
  ReferenceError: window is not defined
  
  - index.html:76 Object.
    E:/js-test/Angularjs-ES6-Demo/src/script/index.html:76:1
  
  - index.html:21 __webpack_require__
    E:/js-test/Angularjs-ES6-Demo/src/script/index.html:21:30
  
  - index.html:67 path
    E:/js-test/Angularjs-ES6-Demo/src/script/index.html:67:18
  
  - index.html:70 
    E:/js-test/Angularjs-ES6-Demo/src/script/index.html:70:10
  
  - index.js:231 HtmlWebpackPlugin.evaluateCompilationResult
    [Angularjs-ES6-Demo]/[[email protected]@html-webpack-plugin]/inde    x.js:231:26
  
  - index.js:117 
    [Angularjs-ES6-Demo]/[[email protected]@html-webpack-plugin]/inde    x.js:117:21
  
  - util.js:16 tryCatcher
    [Angularjs-ES6-Demo]/[[email protected]@bluebird]/js/release/util.js:16:23
  
  - promise.js:512 Promise._settlePromiseFromHandler
    [Angularjs-ES6-Demo]/[[email protected]@bluebird]/js/release/promise.js:512:3    1
  
  - promise.js:569 Promise._settlePromise
    [Angularjs-ES6-Demo]/[[email protected]@bluebird]/js/release/promise.js:569:1    8

I'v been install the html-loader and ngtemplate-loader, and the relative webpack.config.js is:

    module: {
        rules: [
            { 
                test: /\.scss$/, 
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ["css-loader", 'sass-loader']
                  })
            },// ['style-loader', 'css-loader', 'sass-loader']
            { 
                test: /\.js$/, 
                exclude: /node_modules/, 
                use: ['ng-annotate-loader','babel-loader']
            },
            {
                test: /\.html$/,
                use: [
                    { loader:'ngtemplate-loader?relativeTo=' + (path.resolve(__dirname, './src/')) },
                    { loader: 'html-loader' }
                ]
            }
        ]
    },
@yankwan
Copy link
Author

yankwan commented Nov 17, 2017

As I exclude the entry template html file in ngtemplate-loader, it fix the ReferenceError.

update the loader config to :

            {
                test: /\.html$/,
                exclude: path.resolve(__dirname, './src/script/index.html'),
                use: [
                    { loader:'ngtemplate-loader?relativeTo=' + (path.resolve(__dirname, './src/')) },
                    { loader: 'html-loader' }
                ]
            }

but on the console it report the new error :

Uncaught TypeError: Cannot read property 'module' of undefined
    at Object.path (bundle.js?5485e4be7b4888e47389:sourcemap:46483)
    at __webpack_require__ (bundle.js?5485e4be7b4888e47389:sourcemap:20)
    at Object.<anonymous> (bundle.js?5485e4be7b4888e47389:sourcemap:8407)
    at __webpack_require__ (bundle.js?5485e4be7b4888e47389:sourcemap:20)
    at Object.<anonymous> (bundle.js?5485e4be7b4888e47389:sourcemap:53980)
    at __webpack_require__ (bundle.js?5485e4be7b4888e47389:sourcemap:20)
    at Object.defineProperty.value (bundle.js?5485e4be7b4888e47389:sourcemap:66)
    at bundle.js?5485e4be7b4888e47389:sourcemap:69

@yankwan
Copy link
Author

yankwan commented Nov 20, 2017

I found that I should impot the angular import angular from 'angular' before I import other things like view.html or other js file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant