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

Module build failed: TypeError: Cannot read property 'directoryExists' of undefined

Open aderbas opened this issue 10 years ago • 34 comments

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

    Linux, Ubuntu 14.04

  2. Versions. Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

$ ng --version
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.11-webpack.8
node: 6.5.0
os: linux x64
  1. Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

I had the error on a project and decided to create a new one for testing.

$ ng new apptest2
$ cd apptest2
$ ng build

I have not changed anything.

  1. The log given by the failure. Normally this include a stack trace and some more information.
$ ng build
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
 10% building modules 6/12 modules 6 active ...de_modules/script-loader/addScript.jsTypeError: Cannot read property 'directoryExists' of undefined
    at Object.getAutomaticTypeDirectiveNames (/var/www/html/apptest2/node_modules/typescript/lib/typescript.js:43865:17)
    at State.loadTypesFromConfig (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/host.ts:150:36)
    at new State (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/host.ts:144:14)
    at Object.ensureInstance (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/instance.ts:150:19)
    at compiler (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/index.ts:37:20)
    at Object.loader (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/index.ts:18:18)
    at LOADER_EXECUTION (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:95:14)
    at runSyncOrAsync (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:96:4)
    at iterateNormalLoaders (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:200:2)
    at iterateNormalLoaders (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:189:10)
    at /var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:204:3
    at Object.context.callback (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:87:13)
    at Object.module.exports (/var/www/html/apptest2/node_modules/angular2-template-loader/index.js:32:10)
    at LOADER_EXECUTION (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:95:14)
    at runSyncOrAsync (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:96:4)
    at iterateNormalLoaders (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:200:2)
    at /var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:173:4
    at Storage.finished (/var/www/html/apptest2/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:39:16)
    at /var/www/html/apptest2/node_modules/enhanced-resolve/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3) 'TypeError: Cannot read property \'directoryExists\' of undefined\n    at Object.getAutomaticTypeDirectiveNames (/var/www/html/apptest2/node_modules/typescript/lib/typescript.js:43865:17)\n    at State.loadTypesFromConfig (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/host.ts:150:36)\n    at new State (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/host.ts:144:14)\n    at Object.ensureInstance (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/instance.ts:150:19)\n    at compiler (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/index.ts:37:20)\n    at Object.loader (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/index.ts:18:18)\n    at LOADER_EXECUTION (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:95:14)\n    at runSyncOrAsync (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:96:4)\n    at iterateNormalLoaders (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:200:2)\n    at iterateNormalLoaders (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:189:10)\n    at /var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:204:3\n    at Object.context.callback (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:87:13)\n    at Object.module.exports (/var/www/html/apptest2/node_modules/angular2-template-loader/index.js:32:10)\n    at LOADER_EXECUTION (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:95:14)\n    at runSyncOrAsync (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:96:4)\n    at iterateNormalLoaders (/var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:200:2)\n    at /var/www/html/apptest2/node_modules/loader-runner/lib/LoaderRunner.js:173:4\n    at Storage.finished (/var/www/html/apptest2/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:39:16)\n    at /var/www/html/apptest2/node_modules/enhanced-resolve/node_modules/graceful-fs/graceful-fs.js:78:16\n    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)'
1044ms building modules                                                              
1ms sealing 
0ms optimizing 
0ms basic module optimization 
1ms module optimization 
0ms advanced module optimization 
2ms basic chunk optimization        
0ms chunk optimization 
0ms advanced chunk optimization 
1ms module and chunk tree optimization 
1ms module reviving 
0ms module order optimization 
1ms module id optimization 
2ms chunk reviving 
0ms chunk order optimization 
1ms chunk id optimization 
2ms hashing 
0ms module assets processing 
5ms chunk assets processing 
0ms additional chunk assets processing 
0ms recording 
0ms additional asset processing 
72ms chunk asset optimization
31ms asset optimization
6ms emitting 
Hash: bbc4834236db6d10b21a
Version: webpack 2.1.0-beta.21
Time: 1189ms
            Asset       Size  Chunks             Chunk Names
 styles.bundle.js      29 kB    0, 3  [emitted]  styles
scripts.bundle.js     128 kB    1, 3  [emitted]  scripts
   main.bundle.js  999 bytes    2, 3  [emitted]  main
        inline.js    5.53 kB       3  [emitted]  inline
       styles.map    37.5 kB    0, 3  [emitted]  styles
      scripts.map     150 kB    1, 3  [emitted]  scripts
         main.map   91 bytes    2, 3  [emitted]  main
       inline.map    5.59 kB       3  [emitted]  inline
       index.html  866 bytes          [emitted]  
assets/.npmignore    0 bytes          [emitted]  
chunk    {0} styles.bundle.js, styles.map (styles) 28.5 kB {3} [initial] [rendered]
chunk    {1} scripts.bundle.js, scripts.map (scripts) 128 kB {0} [initial] [rendered]
chunk    {2} main.bundle.js, main.map (main) 793 bytes {1} [initial] [rendered]
chunk    {3} inline.js, inline.map (inline) 0 bytes [entry] [rendered]

ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'directoryExists' of undefined
    at Object.getAutomaticTypeDirectiveNames (/var/www/html/apptest2/node_modules/typescript/lib/typescript.js:43865:17)
    at State.loadTypesFromConfig (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/host.ts:150:36)
    at new State (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/host.ts:144:14)
    at Object.ensureInstance (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/instance.ts:150:19)
    at compiler (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/index.ts:37:20)
    at Object.loader (/var/www/html/apptest2/node_modules/awesome-typescript-loader/src/index.ts:18:18)
 @ multi main
Child html-webpack-plugin for "index.html":
         Asset     Size  Chunks       Chunk Names
    index.html  3.15 kB       0       
    chunk    {0} index.html 687 bytes [entry] [rendered]
  • package.json:
{
  "name": "apptest2",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "3.0.0-rc.1",
    "core-js": "^2.4.0",
    "leaflet": "^0.7.7",
    "rxjs": "5.0.0-beta.11",
    "ts-helpers": "^1.1.1",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/leaflet": "^1.0.31",
    "angular-cli": "1.0.0-beta.11-webpack.8",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.3",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.0"
  }
}

aderbas avatar Sep 06 '16 14:09 aderbas

Just adding 2.2.1 to dev didn't resolve the issue for me, however, then after removing node_modules\.2.2.3@awesome-typescript-loader, the error was gone.

Then I start over with a new project and try to find why 2.2.3 version was included using npm ls, ...and it turned out to be the angular-cli package itself. I'm new to npm so I'm not sure if I understood this correctly, it feels confusing that the cli was dependent on a lib that blocks itself from working normally.

2016-09-07 3 19 41

waterscar avatar Sep 07 '16 07:09 waterscar

@waterscar That's the magic of dynamic transitive dependencies. angular-cli declares the dependency as "awesome-typescript-loader": "^2.2.1",, the ^ is what's important here. That means (in simplified terms): "Any version of the awesome-typescript-loader that looks like '2.x.x'".

At the time the developers declared this dependency, version 2.2.1 was the current version and it worked. But what if the awesome-typescript-loader project publishes new versions 2.2.2 and 2.2.3? Anyone who npm builds his project from that point in time on will get the new 2.2.3 version, which in this case is either not backward compatible (enough) or has a bug.

Whatever it is, dynamic transitive dependencies are bad and we should stop using them.

Edit: oh and the reason it works when manually specified is that by not putting a ^ in your dependency declaration, you say "I want exactly version 2.2.1", and since this matches angular-cli's wish for "something like 2.x.x", npm choses the older, working version.

netmikey avatar Sep 07 '16 08:09 netmikey

The "awesome" fix resolved the issue of trying to access directoryExists on undefined but now there are a half dozen "Type 'Type' is not generic" errors in config.d.ts, router.d.ts and router_state.d.ts:

ERROR in [default] ...\node_modules@angular\router\src\router.d.ts:216:35 Type 'Type' is not generic.

As you can tell it's a Windows machine in this case but otherwise the same RC5 with Typescript 2.0.0 etc.

It's choking on nested generics:

export declare type LoadChildrenCallback = () => Type<any> | Promise<Type<any>> | Observable<Type<any>>;

ghost avatar Sep 09 '16 00:09 ghost

@Toadskin Did you try pinning "typescript": "2.0.0"? I had a lot of errors after generating the project, because a newer typescript version was choosen.

matthiasbalke avatar Sep 09 '16 16:09 matthiasbalke

+1

RicardoVaranda avatar Sep 10 '16 10:09 RicardoVaranda

Adding awesome-typescript-loader pinned to 2.2.1 is a partial solution. I found you must a) clear your npm cache, b) delete node_modules folder from your project, c) remove ^ so you get the precise version you are asking for (2.2.2 versus 2.X.X).

Even then you will get a slew of ERR! messages during npm install (clearly that must be remedied) but the subsequent ng build will succeed.

BTW, the router error referenced above (Type "Type" is not generic) goes away when removing the caret from the @angular/router version.

I wonder if semantic versioning has to be written off as a good idea that fails in practice, because there is no means of ensuring successive 1.X.X versions are compatible with previous 1.X.X versions.

ghost avatar Sep 10 '16 18:09 ghost

I've set awesome-typescript-loader to 2.2.1 without the ^ before doing an npm install on a fresh install of npm since in using docker container and this error is still present has anyone managed to get it working?

RicardoVaranda avatar Sep 10 '16 21:09 RicardoVaranda

Just type this in your project : npm install [email protected]

pdelorme avatar Sep 16 '16 12:09 pdelorme

@pdelorme, this package should be a dev dependency, it's not needed for production. The line should be:

npm install [email protected] --save-dev

vkniazeu avatar Sep 16 '16 14:09 vkniazeu

This has since been fixed, and should be present in beta.14+.

filipesilva avatar Sep 22 '16 00:09 filipesilva

Module build failed: TypeError: Cannot read property 'replace' of undefined at Object.Angular2HMRLoader

version: Angular CLI: 8.0.2 Node: 10.16.0 OS: win32 x64 Angular: ...

Package Version

@angular-devkit/architect 0.800.2 @angular-devkit/core 8.0.2 @angular-devkit/schematics 8.0.2 @schematics/angular 8.0.2 @schematics/update 0.800.2 rxjs 6.4.0

zhang14725804 avatar Jun 11 '19 06:06 zhang14725804

"dependencies": { "@angular/animations": "~4.0.3", "@angular/common": "~4.0.3", "@angular/compiler": "~4.0.3", "@angular/core": "~4.0.3", "@angular/forms": "~4.0.3", "@angular/http": "~4.0.3", "@angular/platform-browser": "~4.0.3", "@angular/platform-browser-dynamic": "~4.0.3", "@angular/platform-server": "~4.0.3", "@angular/router": "~4.0.3", "@angularclass/conventions-loader": "^1.0.13", "@angularclass/hmr": "~1.2.2", "@angularclass/hmr-loader": "~3.0.2", "@types/jquery": "^2.0.34", "@types/snapsvg": "^0.4.28", "angular2-infinite-scroll": "^0.3.5", "angular2-toastr": "^1.0.6", "core-js": "^2.4.1", "echarts": "^3.7.1", "http-server": "^0.9.0", "ie-shim": "^0.1.0", "jquery": "^3.1.1", "ng2-dnd": "^4.0.2", "ng2-select": "^1.2.0", "ng2-validation": "^4.2.0", "ngx-bootstrap": "^1.9.3", "ngx-bootstrap-modal": "^1.1.0", "reflect-metadata": "^0.1.10", "rxjs": "5.0.2", "snapsvg": "^0.5.1", "zone.js": "~0.8.5" }, "devDependencies": { "@angular/cli": "^1.1.1", "@angular/compiler-cli": "~4.0.3", "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", "@types/hammerjs": "^2.0.34", "@types/jasmine": "2.5.45", "@types/node": "^7.0.13", "@types/source-map": "^0.5.0", "@types/uglify-js": "^2.6.28", "@types/webpack": "^2.2.15", "add-asset-html-webpack-plugin": "^1.0.2", "ag-grid": "^13.3.1", "ag-grid-angular": "^13.3.0", "angular2-template-loader": "^0.6.2", "assets-webpack-plugin": "^3.5.1", "awesome-typescript-loader": "3.1.2", "bootstrap-select": "^1.12.4", "codelyzer": "~2.1.1", "copy-webpack-plugin": "^4.0.1", "css-loader": "^0.28.0", "echarts": "^3.7.1", "exports-loader": "^0.6.4", "expose-loader": "^0.7.3", "extract-text-webpack-plugin": "~2.1.0", "file-loader": "^0.11.1", "find-root": "^1.0.0", "gh-pages": "^0.12.0", "html-webpack-plugin": "^2.28.0", "imports-loader": "^0.7.1", "inline-manifest-webpack-plugin": "^3.0.1", "istanbul-instrumenter-loader": "2.0.0", "jasmine-core": "^2.5.2", "json-loader": "^0.5.4", "karma": "^1.6.0", "karma-chrome-launcher": "^2.0.0", "karma-coverage": "^1.1.1", "karma-jasmine": "^1.1.0", "karma-mocha-reporter": "^2.2.3", "karma-remap-coverage": "^0.1.4", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "~2.0.3", "ng-router-loader": "^2.1.0", "ngc-webpack": "~2.0.0", "ngx-echarts": "^1.2.4", "node-sass": "^4.12.0", "npm-run-all": "^4.0.2", "optimize-js-plugin": "0.0.4", "parse5": "^3.0.2", "protractor": "^5.1.1", "raw-loader": "0.5.1", "rimraf": "~2.6.1", "sass-loader": "^6.0.7", "script-ext-html-webpack-plugin": "^1.7.1", "source-map-loader": "^0.2.1", "string-replace-loader": "~1.2.0", "style-loader": "^0.16.1", "to-string-loader": "^1.1.5", "ts-node": "^3.0.2", "tslib": "^1.6.1", "tslint": "~4.5.1", "tslint-loader": "^3.5.2", "typedoc": "^0.5.10", "typescript": "~2.2.2", "url-loader": "^0.5.8", "webpack": "~2.4.1", "webpack-dev-middleware": "^1.10.1", "webpack-dev-server": "~2.4.2", "webpack-dll-bundles-plugin": "^1.0.0-beta.5", "webpack-merge": "~4.1.0" }

zhang14725804 avatar Jun 11 '19 06:06 zhang14725804

@aderbas @sholzmayer @Ranfty @danyel @osmanm786

zhang14725804 avatar Jun 11 '19 08:06 zhang14725804

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.