Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How did you avoid typescript errors not finding node modules? #96

Open
da-mkay opened this issue Jan 26, 2019 · 2 comments
Open

Comments

@da-mkay
Copy link

da-mkay commented Jan 26, 2019

Hi there, nice project! I'm trying to figure out how some things work in your project for better understanding 😄 I hope it's okay to post a question here 👼 .

When importing a node-module in your AppComponent, for example using the following line, it just works:
import * as fs from 'fs';

However, if I try to set up an Angular project manually that I can later open in electron, I am not able to compile, because I get the following error:
error TS2307: Cannot find module 'fs'.
What I did:
I created a simple new Angular 7 app + added a custom webpack config (listing 'fs' as external as in your webpack config) + updated angular.json to use that config (using @angular-builders/custom-webpack:browser and customWebpackConfig-option, exactly as you did). Then run ng build.
NOTE: @types/node and @angular-devkit/build-angular are installed and my editor (VSCode) is not showing any error.

Am I missing something? How do I get the ts-code compiled?

Best regards

@just-jeb
Copy link
Owner

just-jeb commented Jan 29, 2019

Sounds like tsconfig.json issue. Did you override typeRoots by any chance? Maybe Angular build is picking the wrong config?
If you have provided a repository with reproduction I would have had more chances to help you out.

@da-mkay
Copy link
Author

da-mkay commented Jan 29, 2019

Nope, I didn't touch the tsconfig, just using Angular's defaults. I set up a project here. There are just 2 commits. The first one is the output of ng new and the second adds the custom_webpack builder and a custom webpack config declaring fs module as external. Running ng build shows the error that fs is not found. I can fix this by setting "types": ["node"] intsconfig.app.json, but that doesn't seem to be right and in your project it's also not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants