ng build cannot find module

gary69

I am trying to locally test 3 node modules by updating the locations they are being pulled from in their package.json files. The modules are sdk, ng-widget-lib, and frontend. ng-widget-lib depends on sdk and frontend depends on ng-widget-lib. I build sdk locally with babel. I'm running verdaccio as a local npm registry.

I update ng-widget/package.json (the name of the repo/root directory is ng-widget not ng-widget-lib) changing the name to @locals/ng-widget-lib and point the sdk dependency to the local sdk directory. Then run npm install and build with ng build which runs successfully. I then change the name in dist/package.json to @locals/ng-widget-lib and publish to my local registry.

In frontend/package.json I point the ng-widget-lib dependency to @locals/ng-widget-lib (I have tried pointing it to the local directory and not using the local registry but this still doesn't work). I run npm install which downloads the module from my local registry to node_modules/@locals/ng-widget-lib and creates a package-lock.json with ng-widget-lib pointing to the local registry. Then when I run ng build --prod or ng build it fails in the files where I'm importing @locals/ng-widget-lib with error

error TS2307: Cannot find module '@locals/ng-widget-lib'.

I have deleted node_modules and run npm cache clean --force but still the same error. The ng-widget-lib and frontend use angular 8, sdk is typescript. I'm using npm 6.11.3

Here is my tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
gary69

I followed this https://stackoverflow.com/a/48150290/3614578 and was able to import the local module successfully. I put the ngPackage config directly in package.json, and I also didn't have to run npm pack. This is my config in package.json

"ngPackage": {
    "lib": {
        "entryFile": "./projects/ng-widget-lib/src/public_api.ts"
    },
    "whitelistedNonPeerDependencies": [
      "angular",
      "rxjs",
      "tslib",
      "zone.js"
    ]
  }

I was also able to get it to build after installing from my local registry. I followed this https://github.com/angular/angular-cli/wiki/stories-create-library. Basically there is a special command for building angular libraries that needs to be run ng generate library my-lib, and then you have to publish from your dist/<lib-name> folder, not your root folder.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot determine the module for class - ng build --prod

From Dev

NG Build fail in Azure DevOps pipline : Error: Cannot find module '../internal/operators/audit'

From Dev

ng serve: Cannot find module 'tapable'

From Dev

Cannot find module '../build/Release/bson'. NodeJS

From Dev

Cannot find Module "build" in Docker Container

From Dev

Build:Cannot find module OurFirstAppWithFVisualStudio.module.scss

From Dev

Module build failed: Error: Cannot find module 'node-sass'

From Dev

Error: Cannot find module '/app/__sapper__/build' on Cloud Build

From Dev

ng serve : Cannot find module './templates.js'

From Dev

Cannot find module '@angular/compiler' when runnig ng serve

From Dev

Angular 2 - Cannot find module ' ng-factory'

From Dev

Cordova 8.1.1 android build: cannot find module xcode

From Dev

Cannot find module @restart/context/forwardRef during npm build

From Dev

Angular build cannot find module with relative path (on azure dev ops)

From Dev

ionic cordova build android Cannot find module '../pages/Wallet/'

From Dev

Ionic 3: Build in “prod” mode: Cannot find module “.”

From Dev

vercel Cannot find module or type declarations while it works in local build

From Dev

Cordova 4.3.0 - build command returns error Cannot find module 'Q'

From Dev

Cannot find module '../build/Release/opencv4nodejs

From Dev

Error: Cannot find module '../build/Release/bson' on Mac

From Dev

TS2307 Build:Cannot find module 'lodash'

From Dev

code build to create lambda layer - cannot find module

From Dev

Ionic Cordova Build prod: Cannot find module “.” - Typescript version >3

From Dev

Ionic build error Cannot find module './scheduler/Action'

From Dev

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'build\app' imported from build\server.js

From Dev

webpacker Uncaught Error: Module build failed / Cannot find module 'babel-plugin-syntax-dynamic-import'

From Dev

ERROR in ./src/styles.scss .. Module build failed: Error: Cannot find module 'node-sass'

From Dev

Rocket.Chat build failing with error "Cannot find module '../build/Release/sharp.node' "

From Dev

Cannot find module (a custom module)

Related Related

  1. 1

    Cannot determine the module for class - ng build --prod

  2. 2

    NG Build fail in Azure DevOps pipline : Error: Cannot find module '../internal/operators/audit'

  3. 3

    ng serve: Cannot find module 'tapable'

  4. 4

    Cannot find module '../build/Release/bson'. NodeJS

  5. 5

    Cannot find Module "build" in Docker Container

  6. 6

    Build:Cannot find module OurFirstAppWithFVisualStudio.module.scss

  7. 7

    Module build failed: Error: Cannot find module 'node-sass'

  8. 8

    Error: Cannot find module '/app/__sapper__/build' on Cloud Build

  9. 9

    ng serve : Cannot find module './templates.js'

  10. 10

    Cannot find module '@angular/compiler' when runnig ng serve

  11. 11

    Angular 2 - Cannot find module ' ng-factory'

  12. 12

    Cordova 8.1.1 android build: cannot find module xcode

  13. 13

    Cannot find module @restart/context/forwardRef during npm build

  14. 14

    Angular build cannot find module with relative path (on azure dev ops)

  15. 15

    ionic cordova build android Cannot find module '../pages/Wallet/'

  16. 16

    Ionic 3: Build in “prod” mode: Cannot find module “.”

  17. 17

    vercel Cannot find module or type declarations while it works in local build

  18. 18

    Cordova 4.3.0 - build command returns error Cannot find module 'Q'

  19. 19

    Cannot find module '../build/Release/opencv4nodejs

  20. 20

    Error: Cannot find module '../build/Release/bson' on Mac

  21. 21

    TS2307 Build:Cannot find module 'lodash'

  22. 22

    code build to create lambda layer - cannot find module

  23. 23

    Ionic Cordova Build prod: Cannot find module “.” - Typescript version >3

  24. 24

    Ionic build error Cannot find module './scheduler/Action'

  25. 25

    Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'build\app' imported from build\server.js

  26. 26

    webpacker Uncaught Error: Module build failed / Cannot find module 'babel-plugin-syntax-dynamic-import'

  27. 27

    ERROR in ./src/styles.scss .. Module build failed: Error: Cannot find module 'node-sass'

  28. 28

    Rocket.Chat build failing with error "Cannot find module '../build/Release/sharp.node' "

  29. 29

    Cannot find module (a custom module)

HotTag

Archive