question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scoped packages throw compilation errors

See original GitHub issue

When I try to compile an application for production that uses a library which has an NPM scope, it throws errors and fails.

Reproduction Steps

  1. Create a new library: mkdir lib, cd lib, and yo angular2-library
  2. Generate a new clean angular app with angular-cli: ng new app-seed
  3. Modify your library package.json (the one in src, or the dist folder) to be scoped: "name": "@aaa/lib",
  4. Perform an NPM link of your library: npm link and then inside your app: npm link @aaa/lib
  5. Run ng build --prod --aot and see the console error below. Commands ng serve and ng 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:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

19reactions
jdjuancommented, Apr 24, 2017

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:

"name": "@aaa/lib"

AND, you also need to update flatModuleId in your tsconfig.es5.json, like this:

"flatModuleId": "@aaa/lib"

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

4reactions
DaveMonagcommented, Jun 14, 2017

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”.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found