Unable to compile due to unable to find node_modules folder
See original GitHub issueType 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:
- Created 6 years ago
- Comments:14 (6 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
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:
https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
i believe the problem is in
.ng_build/ts/tsconfig.lib.json
when i removed the typeRoots because of
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?