Skip to content

Webpack paths-plugin error when using paths in tsconfig.json: targets.forEach is not a function #9120

@bbottema

Description

@bbottema

Versions

Angular CLI: 1.6.3
Node: 6.10.2
OS: win32 x64
Angular: 5.1.2
... animations, common, compiler, core, forms, http
... platform-browser, platform-browser-dynamic, router

@angular/cli: 1.6.3
@angular/compiler-cli: 5.1.3
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.3
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0

Repro steps

  • Add a "paths" attribute to tsconfig.json
  • run ng serve

Here's my complete tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es6",
      "dom"
    ],
    "paths": {
      "baseUrl": ".",
      "ng-mdb-pro": [
        "src/app/externals/mdb"
      ]
    }
  },
  "include": [
    "node_modules/ng-mdb-pro/**/*.ts",
    "src/**/*.ts"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useWebpackText": true
  },
  "angularCompilerOptions": {
    "debug": false
  },
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

Observed behavior

** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
targets.forEach is not a function
TypeError: targets.forEach is not a function
    at PathsPlugin.Object.keys.forEach.alias (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@ngtools\webpack\src\paths-plugin.js:53:21)
    at Array.forEach (native)
    at new PathsPlugin (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@ngtools\webpack\src\paths-plugin.js:49:28)
    at Compiler.compiler.plugin (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:466:45)
    at Compiler.applyPlugins (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\tapable\lib\Tapable.js:61:14)
    at Compiler.createNormalModuleFactory (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:471:8)
    at Compiler.newCompilationParams (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:483:30)
    at Compiler.compile (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:491:23)
    at compiler.applyPluginsAsync.err (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:83:18)
    at next (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\tapable\lib\Tapable.js:202:11)
    at Compiler.compilerInvalid (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\webpack-dev-middleware\lib\Shared.js:161:5)
    at next (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\tapable\lib\Tapable.js:204:14)
    at Compiler.compiler.plugin (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\CachePlugin.js:48:5)
    at Compiler.applyPluginsAsyncSeries (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\tapable\lib\Tapable.js:206:13)
    at Watching._go (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:48:17)
    at Watching.compiler.readRecords.err (D:\workstation\mdbootstrap pro\ng-admin-pro\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:40:9)

Desired behavior

I have a 3rd party library that has both a zip release as well as a npm release. I need to be able to easily switch between both, without having to change the import statements. So I need an alias, for which according to this comment I'm supposed to use the paths attribute in tsconfig.json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions