Repository navigation
Error resolving symbol NgModule when importing module using tsconfig compilerOptions.paths #7714
Description
Activity
Update: https://github.com/dohpaz42/aot-static-module/pull/1
I would like to convert this into a feature request that the error messages be updated to at least show the (resolved/real) path(s) used to look for the imports, so that if in the future this happens because a misconfiguration, it would be quicker to realize the problem (using
ng build --verbosein this case does nothing).Here is another repro:
.angular-cli.json: https://github.com/dherges/nx-sandbox/blob/master/.angular-cli.json#L9
tsconfig.app.json: https://github.com/dherges/nx-sandbox/blob/master/tsconfig.app.json#L8-L10
It chokes when the
compilerOptions.pathstarget is located as a parent of theapp.root(not a sub folder inapps/u-app/srcin above example)$ ng build ERROR in ./apps/u-app/src/app/app.module.ts Module not found: Error: Can't resolve '@nx-sandbox/i-lib' in '~/nx-sandbox\apps\u-app\src\app' resolve '@nx-sandbox/i-lib' in '~/nx-sandbox\apps\u-app\src\app' Parsed request is a module using description file: ~/nx-sandbox\package.json (relative path: ./apps/u-app/src/app) Field 'browser' doesn't contain a valid alias configuration /* ... (truncated) ... */ [~\nx-sandbox\apps\u-app\src\app\node_modules] [~\nx-sandbox\apps\u-app\src\node_modules] [~\nx-sandbox\apps\u-app\node_modules] [~\nx-sandbox\apps\node_modules] [~\node_modules] /* ... (truncated, other folders up until disk root) ... */ [\drive\node_modules] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib.ts] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib.js] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib.ts] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib.js] [~\nx-sandbox\node_modules\@nx-sandbox\i-lib] [~\nx-sandbox\@nx-sandbox\i-lib] [~\nx-sandbox\@nx-sandbox\i-lib.ts] [~\nx-sandbox\@nx-sandbox\i-lib.js] [~\nx-sandbox\@nx-sandbox\i-lib] [~\nx-sandbox\@nx-sandbox\i-lib] [~\nx-sandbox\@nx-sandbox\i-lib.ts] [~\nx-sandbox\@nx-sandbox\i-lib.js] [~\nx-sandbox\@nx-sandbox\i-lib]
Workarounds are:
- copy folders to a sub-folder of
app.root, e.g. forimport ... from '@my/lib'- copy the folder to
./apps/*/src/@my/lib
- copy the folder to
- symlink (or copy) the folders to
node_modules, e.g. forimport ... from '@my/lib'- symlink from
node_modules/@my/libto the target folder./dist/libs/my-lib - or copy
./dist/libs/my-libtonode_modules/@my/lib
- symlink from
- copy folders to a sub-folder of
Confirmed this is an issue. Prevents people from developing libraries in the same project as their app if they want to use the built version of their library to build their app against.
More details and reproduction available here:
Reacted by David Herges, Jamie Briant, Michael Prentice, Abner Souza, Yönet and Aliaksei VarabeiAny update on this bug? Trying to use path within Nx and having the same issue
ERROR in Error: Metadata version mismatch for module C:/Users/Chennaiyan/angular4-proj/Angular4MongoDB/node_modules/@angular/material/core/typings/index.d.ts, found version 4, expected 3, resolving symbol AppModule in
C:/Users/Chennaiyan/angular4-proj/Angular4MongoDB/src/app/app.module.ts, resolving symbol AppModule in C:/Users/Chennaiyan/angular4-proj/Angular4MongoDB/src/app/app.module.ts
at syntaxError (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler\bundles\compiler.umd.js:1729:34)
at simplifyInContext (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler\bundles\compiler.umd.js:24979:23)
at StaticReflector.simplify (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler\bundles\compiler.umd.js:24991:13)
at StaticReflector.annotations (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler\bundles\compiler.umd.js:24418:41)
at _getNgModuleMetadata (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler-cli\src\ngtools_impl.js:138:31)
at _extractLazyRoutesFromStaticModule (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler-cli\src\ngtools_impl.js:109:26)
at Object.listLazyRoutesOfModule (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler-cli\src\ngtools_impl.js:53:22)
at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@angular\compiler-cli\src\ngtools_api.js:91:39)
at AotPlugin._getLazyRoutesFromNgtools (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@ngtools\webpack\src\plugin.js:240:66)
at _donePromise.Promise.resolve.then.then.then.then.then (C:\Users\Chennaiyan\angular4-proj\Angular4MongoDB\node_modules@ngtools\webpack\src\plugin.js:493:24)
at
at process._tickCallback (internal/process/next_tick.js:160:7)@hansl @filipesilva It would be really nice to at least get some labels on this issue. Perhaps it was resolved in the v6 updates?
Based on some of my tests and https://github.com/dherges/ng-packaged, this appears to be fixed in v6.
@jasonaden - Can we test this issue and mark this issue as 'Closed' if @Splaktar is correct?
Thanks!
Reacted by Michael Prentice@filipesilva @hansl Can this be closed now?
Reacted by Michael PrenticeI think so, yes. Our lib generation and consumption journey makes the library in the same project, and we test that it works.
Reacted by Michael Prenticeangular-automatic-lock-bot commented
on Sep 8, 2019 More actionsThis 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.
- locked and limited conversation to collaborators
on Sep 8, 2019
Bug Report or Feature Request (mark with an
x)Versions.
OS
macOS Sierra 10.12.6
ng--version
node --version
v8.5.0npm --version
5.3.0Repro steps.
Fresh install using
ng new, no added packages. Rearranged my directory structure so that my app is a subdirectory of a web directory. Reconfiguredtsconfig.jsonin the root so that it uses an@appprefix for importing from the./web/app/srcfolder. Modifymain.tsto import from'@app/app.module'instead of'./src/app.module'.Sample repo demonstrates the issue; the README contains commands run (both non-AOT and AOT) and the two different (but related) error messages:
https://github.com/dohpaz42/aot-static-module
The log given by the failure.
Without AOT
With AOT
Desired functionality.
I am trying to structure my application so that I can use the
@-style references when importing local code. It works well for non-modules, but when I go to import any module defined by the@NgModuleannotation, I get the above errors. Ideally, I would expect Angular's build process to be able to compile my code regardless of how I reference imports (assuming it's set up correctly).e.g.
Mention any other details that might be useful.
The
.angular-cli.json,tsconfig.json, andtsconfig.app.jsonare copied directly from the project where I discovered this problem.