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.

Unable to compile due to unable to find node_modules folder

See original GitHub issue

Type of Issue

[X ] Bug Report
[ ] Feature Request

Description

I have a global variable that has its own typings found in node_modules/@types/google.analytics.

[debug] ngc C:\Dev\ng\gsf.google-analytics\.ng_build/ts/tsconfig.lib.json, { basePath: C:\Dev\ng\gsf.google-analytics\.ng_build/ts })

BUILD ERROR
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:22:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:32:13: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:33:13: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:34:13: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:45:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:60:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:65:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:75:9: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:88:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:95:5: Cannot find name 'ga'.
Error: Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:22:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:32:13: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:33:13: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:34:13: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:45:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:60:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:65:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:75:9: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:88:5: Cannot find name 'ga'.
Error at C:/Dev/ng/gsf.google-analytics/.ng_build/ts/src/app/services/google-analytics.service.ts:95:5: Cannot find name 'ga'.
    at new UserError (C:\Dev\ng\gsf.google-analytics\node_modules\@angular\tsc-wrapped\src\tsc.js:27:28)
    at check (C:\Dev\ng\gsf.google-analytics\node_modules\@angular\tsc-wrapped\src\tsc.js:93:15)
    at Tsc.typeCheck (C:\Dev\ng\gsf.google-analytics\node_modules\@angular\tsc-wrapped\src\tsc.js:173:9)
    at C:\Dev\ng\gsf.google-analytics\node_modules\@angular\tsc-wrapped\src\main.js:122:23

FYI: it works with command ng build. The app that uses ng builds imports the module directly.

How To Reproduce

This is my folder structure

\ node_modules
|
\ src
|    |
|    \ app
|        | 
|        \ services
|             |
|             \ module.ts
|
\ ng-package.json
\ public_api.ts
\ package.json

public_api.ts

export * from './src/app/services/google-analytics.module';

ng-package.json

{
    "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
    "lib": {
      "entryFile": "public_api.ts"
    }
  }

Expected Behaviour

Expect it to find the ga declarations and tsc should build it successfully.

Version Information

ng-packagr: v1.4.0
node: v7.10.0
@angular: v4.4.4
rxjs: v5.4.3
zone.js: v0.8.18
@angular/cli: v1.4.5
typescript: v2.3.3

please include any version information that might be relevant, e.g. other third-party libraries

Additional Information

included only the relevant parts

package.json

"devDependencies": {
 "@types/google.analytics": "0.0.35",
}

tsconfig.json

"compilerOptions": {
  "typeRoots": [
      "node_modules/@types"
    ],
}

Used in a service

// not needed for explicit import of ga as typeRoot contains declaration
ga('send', 'pageview', this.location.path(true));

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BenjaminDoblercommented, Oct 26, 2017

The strange thing is that it`s working for me now with or without the typeRoots. Not sure what else i changed. For the visibility it says in the tsconfig doc:

@types, typeRoots and types

By default all visible “@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within ./node_modules/@types/, …/node_modules/@types/, …/…/node_modules/@types/, and so on.

If typeRoots is specified, only packages under typeRoots will be included

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

1reaction
jonyeezscommented, Oct 12, 2017

i believe the problem is in .ng_build/ts/tsconfig.lib.json

when i removed the typeRoots because of

By default all visible “@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within ./node_modules/@types/, …/node_modules/@types/, …/…/node_modules/@types/, and so on.

it compiled correctly for me and now i have my files in the dist folder.

I’m wondering why this isn’t an issue for everyone else?

What is wrong with my setup?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What could cause an error related to npm not being able to ...
Delete node_modules folder manually. · Open command prompt , go to path angular folder and run Yarn. · Run angular\nswag\refresh.bat. · Run npm ......
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >
Npm install command failing with message "could not find ...
I was following the project setup. When I run the npm install command, npm starts downloading the dependencies. But then, suddenly, it stops ......
Read more >
Check in your node_modules folder - seriesci blog
First of all remove node_modules from your .gitignore file. This is huge and you will suddenly see a lot of untracked files on...
Read more >
Common TypeScript module problems and how to solve them
Solution 1: Locate the correct directory ; "compilerOptions": ; "baseUrl": ; ".", ; "paths": ; "express": ...
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