Scoped packages throw compilation errors
See original GitHub issueWhen I try to compile an application for production that uses a library which has an NPM scope, it throws errors and fails.
Reproduction Steps
- Create a new library:
mkdir lib
,cd lib
, andyo angular2-library
- Generate a new clean angular app with angular-cli:
ng new app-seed
- Modify your library
package.json
(the one insrc
, or thedist
folder) to be scoped:"name": "@aaa/lib",
- Perform an
NPM link
of your library:npm link
and then inside your app:npm link @aaa/lib
- Run
ng build --prod --aot
and see the console error below. Commandsng serve
andng build
work well.
You can also clone this repo and jump to step 3.
Error
ERROR in C:/Users/jherrera/repos/PROD-ISSUE3/app-seed/src/$$_gendir/app/app.component.ngfactory.ts (1,1): Cannot find module 'lib'.
ERROR in C:/Users/jherrera/repos/PROD-ISSUE3/app-seed/src/$$_gendir/node_modules/@aaa/lib/lib.ngfactory.ts (1,1): Cannot find module 'lib'.
ERROR in C:/Users/jherrera/repos/PROD-ISSUE3/app-seed/src/$$_gendir/app/app.module.ngfactory.ts (1,1): Cannot find module 'lib'.
ERROR in C:/Users/jherrera/repos/PROD-ISSUE3/app-seed/src/$$_gendir/app/app.module.ngfactory.ts (1,1): Cannot find module 'lib'.
ERROR in C:/Users/jherrera/repos/PROD-ISSUE3/app-seed/src/$$_gendir/app/app.component.ngfactory.ts (1,1): Cannot find module 'lib'.
ERROR in ./src/$$_gendir/app/app.module.ngfactory.ts
Module not found: Error: Can't resolve 'lib' in 'C:\Users\jherrera\repos\PROD-ISSUE3\app-seed\src\$$_gendir\app'
@ ./src/$$_gendir/app/app.module.ngfactory.ts 23:0-31
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./src/$$_gendir/app/app.component.ngfactory.ts
Module not found: Error: Can't resolve 'lib' in 'C:\Users\jherrera\repos\PROD-ISSUE3\app-seed\src\$$_gendir\app'
@ ./src/$$_gendir/app/app.component.ngfactory.ts 10:0-31
@ ./src/$$_gendir/app/app.module.ngfactory.ts
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in C:/Users/jherrera/repos/PROD-ISSUE3/app-seed/src/$$_gendir/node_modules/@aaa/lib/lib.ngfactory.ts (1,1): Cannot find module 'lib'.
ERROR in ./src/$$_gendir/~/@aaa/lib/lib.ngfactory.ts
Module not found: Error: Can't resolve 'lib' in 'C:\Users\jherrera\repos\PROD-ISSUE3\app-seed\src\$$_gendir\node_modules\@aaa\lib'
@ ./src/$$_gendir/~/@aaa/lib/lib.ngfactory.ts 18:0-31
@ ./src/$$_gendir/app/app.component.ngfactory.ts
@ ./src/$$_gendir/app/app.module.ngfactory.ts
@ ./src/main.ts
@ multi ./src/main.ts
Environment
- NPM: 4.5.0
- Node: 7.9.0
- Angular CLI: 1.0.0
- Generator-angular2-libary: 9.0.0
- OS: Windows 10
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Use scoped packages with Jest - Stack Overflow
I am developing an app with react-native and typescript and doing the tests with Jest, but I have a problem when I use...
Read more >The "Cannot find symbol" Compilation Error - Baeldung
In this tutorial, we'll review what compilation errors are. Then we'll specifically explain the “cannot find symbol” error and how it's ...
Read more >How to Resolve The Cannot Find Symbol Error in Java - Rollbar
The most common triggers for the cannot find symbol compile-time error include: missing variable and method declarations;; out-of-scope ...
Read more >Error Handling — The Swift Programming Language (Swift 5.7)
A throwing function propagates errors that are thrown inside of it to the scope from which it's called. Note. Only throwing functions can...
Read more >Java Compile Errors/Warnings Preferences - IBM
When enabled, the compiler will issue an error or a warning whenever a static field or method is accessed with an expression receiver....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nevermind I just fixed. It turns out that whenever you are creating scoped packages you want to update the package name in the
package.json
like this:AND, you also need to update
flatModuleId
in yourtsconfig.es5.json
, like this:Once you do that, you have scoped packages working correctly.
PS: We can close this now, but don’t you think it is worth creating a wiki page for people who want to create scoped packages with this generator? I really spend a few days trying to figure it out @jvandemo
Thanks so much for this @jdjuan ! I’d tried the same fix before but I’d made the mistake of changing the “flatModuleOutFile” to include the scope too, which stopped it from building. Anyone else that made the same mistake, ONLY change “name” and “flatModuleId”, you don’t need to change “flatModuleOutFile”.