angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

1.0.0-beta.30 - Webpack compile fails.

Open JFrankfurt opened this issue 9 years ago • 12 comments

Please provide us with the following information:

OS?

Windows 10

Versions.

@angular/cli: 1.0.0-beta.30
node: 7.5.0
os: win32 x64
@angular/common: 2.4.6
@angular/compiler: 2.4.6
@angular/core: 2.4.6
@angular/forms: 2.4.6
@angular/http: 2.4.6
@angular/platform-browser: 2.4.6
@angular/platform-browser-dynamic: 2.4.6
@angular/router: 3.4.6
@angular/cli: 1.0.0-beta.30
@angular/compiler-cli: 2.4.6
@ngtools/webpack: 1.2.4 <-- added per other threads

Repro steps.

ng serve works as expected in a new application, but for my current project it only serves the html shell.

The log given by the failure.

I got these errors in beta.24, but everything still worked as intended, so I didn't think much of it.

λ ng serve
** NG Live Development Server is running on http://localhost:4200. **
Hash: 55ff5c0649968c95bb51
Time: 14063ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 222 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.map (main) 94.9 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.map (styles) 9.98 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.map (vendor) 3.45 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]

ERROR in (moduleMetadata.imports || []).filter is not a function
webpack: Failed to compile.

Mention any other details that might be useful.

package.json

{
  "name": "search-app",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "^3.3.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.30",
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

angular-cli.json

{
  "project": {
    "version": "1.0.0-beta.30",
    "name": "search-app"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "prefixInterfaces": false,
    "inline": {
      "style": false,
      "template": false
    },
    "spec": {
      "class": false,
      "component": false,
      "directive": false,
      "module": false,
      "pipe": false,
      "service": false
    }
  }
}

JFrankfurt avatar Feb 03 '17 16:02 JFrankfurt

I'm having the exact same problem after updating to beta-30.

  • "ng serve" will only serve the index.html shell without the built files.
  • "ng build" will not generate the built files either dist/.

I also noticed that the build triggered by a file change while under "ng serve", will add the built files to the index.html, the application works after this.

I followed other threads suggestions of adding @ngtools/[email protected] and [email protected] with no luck.

jmsegrev avatar Feb 03 '17 18:02 jmsegrev

This may or may not be related but I had a problem with ngServe not kicking off browser after building changes and the fix had to do with webpack.

#4338

L0G1C avatar Feb 03 '17 18:02 L0G1C

@L0G1C not related, I think. I followed that thread pretty closely and it didn't solve the problem.

JFrankfurt avatar Feb 03 '17 20:02 JFrankfurt

Hi, I think I have got similar problem with you

@angular/cli: 1.0.0-beta.30
node: 6.9.5
os: darwin x64
@angular/common: 2.4.6
@angular/compiler: 2.4.6
@angular/core: 2.4.6
@angular/forms: 2.4.6
@angular/http: 2.4.6
@angular/platform-browser: 2.4.6
@angular/platform-browser-dynamic: 2.4.6
@angular/router: 3.4.6
@angular/cli: 1.0.0-beta.30
@angular/compiler-cli: 2.4.6

and I got the following problems when I try to do ng serve with angular/cli (beta.30)


Cannot read property 'length' of undefined

TypeError: Cannot read property 'length' of undefined

    at createSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:8980:109)

    at parseSourceFileWorker (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:8940:26)

    at Object.parseSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:8899:26)

    at Object.createSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:8727:29)

    at WebpackCompilerHost.getSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@ngtools/webpack/src/compiler_host.js:293:27)

    at findSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45859:29)

    at processSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45790:27)

    at /Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45901:17

    at Object.forEach (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:1115:30)

    at processReferencedFiles (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45899:16)

    at findSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45884:21)

    at processSourceFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45790:27)

    at processRootFile (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45694:13)

    at /Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45151:60

    at Object.forEach (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:1115:30)

    at Object.createProgram (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/typescript/lib/typescript.js:45151:16)

    at AotPlugin._setupOptions (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@ngtools/webpack/src/plugin.js:161:28)

    at new AotPlugin (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@ngtools/webpack/src/plugin.js:21:14)

    at Object.exports.getNonAotConfig (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@angular/cli/models/webpack-configs/typescript.js:26:13)

    at new NgCliWebpackConfig (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@angular/cli/models/webpack-config.js:24:37)

    at Class.run (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@angular/cli/tasks/build.js:16:29)

    at Class.buildRun (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@angular/cli/commands/build.run.js:12:22)

    at Class.run (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@angular/cli/commands/build.js:40:47)

    at Class.<anonymous> (/Users/xxxxxx-dev/MyDev/linkfornew/node_modules/@angular/cli/ember-cli/lib/models/command.js:134:17)

    at process._tickCallback (internal/process/next_tick.js:103:7)



"ng serve" ---> Error. "ng build" ---> Error.

I have tried the advice, which is installing [email protected] "npm install @ngtools/[email protected] --save". After I installed the [email protected] the problem gone.

infinitysky avatar Feb 03 '17 20:02 infinitysky

I spent a solid 6 hours working on this. Ended up just rolling back to 1.0.0-beta.26

JFrankfurt avatar Feb 03 '17 21:02 JFrankfurt

I am having what I imagine is a related problem. If I run "ng serve" it picks up any changes, compiles them and displays correctly. But if I make a change to a directive (and only a directive - as simply as changing the color desired in the example Highlight directive) it does not notice the change and rebuild the project and update the browser. If I manually restart the browser, it still does not show the change (confirming it isn't seeing it and building it). If I restart "ng serve" it sees it, builds in and shows it correctly, but then if I change a directive again, it doesn't see that change. I am also running beta.30

enginpost avatar Feb 06 '17 15:02 enginpost

@JFrankfurt how do you roll back to version 1.0.0-beta.26?

After running these: npm uninstall -g angular-cli @angular/cli npm cache clean npm install -g [email protected]

Then, I tried this: ng --version This was my result: angular-cli: 1.0.0-beta.26 node: 7.2.1 os: darwin x64 @angular/cli: 1.0.0-beta.30 @angular/common: 2.4.7 @angular/compiler: 2.4.7 @angular/core: 2.4.7 @angular/forms: 2.4.7 @angular/http: 2.4.7 @angular/material: 2.0.0-beta.1 @angular/platform-browser: 2.4.7 @angular/platform-browser-dynamic: 2.4.7 @angular/router: 3.4.7 @angular/compiler-cli: 2.4.7

As you can see @angular/cli: 1.0.0-beta.30 is still there

apapatp avatar Feb 10 '17 01:02 apapatp

My random guess is that you ran it in a project w/ node_modules or package.json that contain the old version.

JFrankfurt avatar Feb 10 '17 03:02 JFrankfurt

I'm not sure if the following issue is Angular-CLI related or not. Nevertheless I'm reporting it because I haven't encountered this problem with previous versions of the CLI. If I import lodash, ng serve fails to compile a new app unless I fiddle with tsconfig triggering a save.

    @angular/cli: 1.0.0-beta.31
    node: 6.9.4
    os: win32 x64
    editor: VS Code 1.9.1

Steps to reproduce

  1. ng new bugdemo

  2. npm i -S lodash-es

  3. npm i -D @types/lodash-es

  4. Edit app.component.ts

    import { isArray } from 'lodash-es';
    ⋮
    test = isArray([1, 2]) ? 'Y' : 'N';
    
  5. ng serve yields:

    ERROR in /src/app/app.component.ts (2,10):
    Module '"/node_modules/@types/lodash/index"' has no exported member 'isArray'.)
    webpack: Failed to compile.
    
  6. While ng serve is still running, tweaking \src\tsconfig.json to trigger a save yields:

    webpack: Compiled successfully
    

This issue is fixed in 1.0.0-beta.32.3

CalvinDale avatar Feb 11 '17 14:02 CalvinDale

OK, I think I just solved my problem. Firstly, I used putting all the library files under src/library, but I do not know somehow the ng server not compatible for this action. After I recreated a new project folder and putting the src/app into the new project folder (AAA/src/app -> BBB/src/app)everything is ok... So I moved all library files to BBB/library and modified the angular-cli.json file to load these libraries and style files. Now the project is running perfectly.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "version": "1.0.0-beta.31",
    "name": "ng2frontend"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        
        "../library/vendor/fontawesome/css/font-awesome.css",
        "../library/vendor/metisMenu/dist/metisMenu.css",
        "../library/vendor/animate.css/animate.css",
        "../library/vendor/bootstrap/dist/css/bootstrap.css",
        "../library/fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css",
        "../library/fonts/pe-icon-7-stroke/css/helper.css",
        "../library/vendor/sweetalert2/dist/sweetalert2.css",
        "../library/vendor/toastr/build/toastr.min.css" ,
        "../library/styles/style.css"
        


      ],
      "scripts": [


       "../library/vendor/jquery/dist/jquery.min.js",
       "../library/vendor/slimScroll/jquery.slimscroll.min.js",
        "../library/vendor/jquery-ui/jquery-ui.min.js",

       "../library/vendor/metisMenu/dist/metisMenu.min.js",
      

       "../library/vendor/sweetalert2/dist/sweetalert2.js",
       "../library/vendor/toastr/build/toastr.min.js",



       "../library/bootstrap/dist/js/bootstrap.js",

       "../library/scripts/homer.js",

       "../library/chart/Chart.min.js"




     ],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "prefixInterfaces": false,
    "inline": {
      "style": false,
      "template": false
    },
    "spec": {
      "class": false,
      "component": true,
      "directive": true,
      "module": false,
      "pipe": true,
      "service": true
    }
  }
}

ng --version :

angular/cli: 1.0.0-beta.31
node: 6.9.1
os: darwin x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.7


infinitysky avatar Feb 14 '17 12:02 infinitysky

@apapatp you did not remove the angular-cli from your project/node_modules the ng-cli not only installed as global service but also been installed into your project. Therefore, to remove the ng-cli from your project, you need execute npm remove angular-cli @angular/cli (without the -g ) at your project path.

infinitysky avatar Feb 14 '17 12:02 infinitysky

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.