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

AOT compilation with npm linked module #2763

Closed
PonyLux opened this issue Oct 18, 2016 · 4 comments
Closed

AOT compilation with npm linked module #2763

PonyLux opened this issue Oct 18, 2016 · 4 comments
Labels
needs: investigation Requires some digging to determine if action is needed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix

Comments

@PonyLux
Copy link

PonyLux commented Oct 18, 2016

OS?

Windows 7

Versions.

ng --version

angular-cli: 1.0.0-beta.17
node: 6.5.0

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

I made 3 projects:

ng new app --style=sass

ng new auth --style=sass

ng new common --style=sass

Then I linked common and auth to app:

cd auth
npm install
npm link
cd ../common
npm install
npm link
cd ../app
npm link auth
npm link common
npm install

First, I get an error
Unexpected value 'CommonModule' imported by the module 'AppModule' Error: Unexpected value 'CommonModule' imported by the module 'AppModule'

While running ng serve.
I saw that this error was fix by the PR #2291

So I tryied to copy/paste the fix = > then ng serve worked.

I try after that to compile in AOT mode but I get exactly the same error

The command I run:
ng build --target=production --aot

The log given by the failure.

$ ng build --target=production --aot                                                                   0% compilingUnexpected value 'CommonModule' imported by the module 'AppModule'
Error: Unexpected value 'CommonModule' imported by the module 'AppModule'
    at C:\xampp\htdocs\front\app\node_modules\@angular\compiler\bundles\compiler.umd.js:14126:37
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (C:\xampp\htdocs\front\app\node_modules\@angular\compiler\bundles\compiler.umd.js:14111:46)
    at C:\xampp\htdocs\front\app\node_modules\@angular\compiler\bundles\compiler.umd.js:12952:58
    at Array.forEach (native)
    at OfflineCompiler.analyzeModules (C:\xampp\htdocs\front\app\node_modules\@angular\compiler\bundles\compiler.umd.js:12951:21)
    at CodeGenerator.codegen (C:\Users\iminar\Dev\angular\modules\@angular\compiler-cli\src\codegen.ts:110:45)
    at AotPlugin._make (C:\xampp\htdocs\front\app\node_modules\@ngtools\webpack\src\plugin.js:186:43)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\@ngtools\webpack\src\plugin.js:151:75)
    at Compiler.applyPluginsParallel (C:\xampp\htdocs\front\app\node_modules\tapable\lib\Tapable.js:156:14)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:463:8)
    at Compiler.applyPluginsAsync (C:\xampp\htdocs\front\app\node_modules\tapable\lib\Tapable.js:73:70)
    at Compiler.compile (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:456:7)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:219:10)
    at Compiler.readRecords (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:367:10)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:216:9)
    at next (C:\xampp\htdocs\front\app\node_modules\tapable\lib\Tapable.js:81:11)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\webpack\lib\CachePlugin.js:34:58)
    at Compiler.applyPluginsAsync (C:\xampp\htdocs\front\app\node_modules\tapable\lib\Tapable.js:85:13)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:213:8)
    at next (C:\xampp\htdocs\front\app\node_modules\tapable\lib\Tapable.js:81:11)
    at Compiler.<anonymous> (C:\xampp\htdocs\front\app\node_modules\webpack\lib\node\NodeEnvironmentPlugin.js:23:3)
    at Compiler.applyPluginsAsync (C:\xampp\htdocs\front\app\node_modules\tapable\lib\Tapable.js:85:13)
    at Compiler.run (C:\xampp\htdocs\front\app\node_modules\webpack\lib\Compiler.js:210:7)
    at C:\xampp\htdocs\front\app\node_modules\angular-cli\tasks\build-webpack.js:26:29
    at Class.run (C:\xampp\htdocs\front\app\node_modules\angular-cli\tasks\build-webpack.js:25:16)
    at Class.run (C:\xampp\htdocs\front\app\node_modules\angular-cli\commands\build.js:50:26)
    at Class.<anonymous> (C:\xampp\htdocs\front\app\node_modules\angular-cli\lib\models\command.js:152:17)
    at tryCatch (C:\xampp\htdocs\front\app\node_modules\rsvp\dist\lib\rsvp\-internal.js:215:12)
    at invokeCallback (C:\xampp\htdocs\front\app\node_modules\rsvp\dist\lib\rsvp\-internal.js:230:13)
    at C:\xampp\htdocs\front\app\node_modules\rsvp\dist\lib\rsvp\then.js:29:16
    at flush (C:\xampp\htdocs\front\app\node_modules\rsvp\dist\lib\rsvp\asap.js:85:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Mention any other details that might be useful.

The package.json

"dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "core-js": "2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "1.1.1",
    "zone.js": "0.6.23",
    "auth": "0.0.0",
    "common": "0.0.0"
  },
  "devDependencies": {
    "@types/jasmine": "2.2.30",
    "@types/node": "6.0.42",
    "angular-cli": "1.0.0-beta.17",
    "codelyzer": "0.0.26",
    "jasmine-core": "2.4.1",
    "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.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }

Note: I get the same result if I use the master instead of the last release.

@Meligy
Copy link
Contributor

Meligy commented Oct 19, 2016

An earlier version of this comment said:

The real problem here is not the npm linking, but trying to use the CLI project as a library. This is an unsupported scenario unfortunately. See #2732 (comment)

I now realise that this wrong, as the comment actually says (highlight mine):

I don't have any specific support for that, no.The recommended approach would be to create a third project, like a library, that both apps depended on.

Sorry for confusion.

@clydin
Copy link
Member

clydin commented Oct 19, 2016

Libraries should be using peer dependencies for the needed angular packages. (This is why --aot is failing).

PR #2291 is forcing node resolution to only use your main app's node_modules. It is essentially hiding the actual problem and also breaking more complicated dependency graphs. The problem is awesome-typescript-loader's dependency resolution. The loader appears to not be compensating for TS 2.0+'s use of realpath on symlinks which results in node's module resolution algorithm being executing on the wrong directory hierarchy.

@filipesilva filipesilva added type: bug/fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent feature: aot needs: investigation Requires some digging to determine if action is needed labels Oct 23, 2016
@hansl hansl modified the milestone: RC1 Nov 11, 2016
@hansl hansl removed this from the RC1 milestone May 2, 2017
@filipesilva
Copy link
Contributor

#6292 adds guidance for linked libraries, but requires 1.1.0-rc.0 minimum.

@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
needs: investigation Requires some digging to determine if action is needed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Projects
None yet
Development

No branches or pull requests

5 participants