Skip to content

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

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

Closed
bbottema opened this issue Jan 7, 2018 · 4 comments

Comments

@bbottema
Copy link

bbottema commented Jan 7, 2018

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.

@Toxicable
Copy link

"compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "ng-mdb-pro": [
        "src/app/externals/mdb"
      ]
    }
  },

@clydin
Copy link
Member

clydin commented Jan 8, 2018

Closing as answered by @Toxicable. The baseUrl option should not be within the paths option.

@clydin clydin closed this as completed Jan 8, 2018
@bbottema
Copy link
Author

bbottema commented Jan 9, 2018

Oh man I feel stupid for such a simple mistake. Sorry for wasting your time :/

I'll give the new config a spin.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants