-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[v6] Electron: Module not found: Error: Can't resolve 'fs' #10681
Comments
I cannot use handlebarjs for the same reason :( |
I've been running into the same problem. Actually, I only need to use |
I've been running into the same problem. For
As a temporary solution, I changed |
I suspect I'm getting the same error using libsodium-sumo. After upgrading to angular 6 I get
Should be easily reproducable on this branch. Frustratingly, the path module isn't used at all in libsodium.js when used in a browser - it exists only when used in node. It's presence seems to trigger this error. If I delete references to path, everything works including libsodium crypto. |
Same issue... After attempting to upgrade to angular-cli v6, I get the following when attempting to run
|
Same issue here when using
|
I've found a "temporary" hack to make this work here: #4227 (comment) You can also use |
Did you try it? |
I guess it depends how your lib imports its dependencies, it works for electron and fs, but I just tried rxdb and the "pouchdb-adapter-localstorage" that imports "stream" fails :( |
My issue was solved by using Tip found here: https://stackoverflow.com/questions/50234196/after-updating-from-angular-5-to-6-i-keep-getting-the-error-cant-resolve-timer |
Same error here with fs and lokijs |
Same error with path here |
Same here with These changes in this commit seem to be responsible for it: angular/devkit@8e7658a#diff-085e357d25d94ae495a662c157178fb0L103 |
This should be address as soon as possible. It blocks many people on ng6 upgrade. |
By the way this is the reasoning behind this change #9827 (comment) and the relevant PR #9812 that is later ported in angular/devkit@8e7658a#diff-085e357d25d94ae495a662c157178fb0L103 I really hope there would be a reasonable solution - for now the best I can figure out is an option to override / supplement webpack configuration so that nodejs shimming can be defined per project. Workaround (the best one I found, thanks @niespodd): https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d |
Workaround: I've found a workaround that works for me: I downgraded |
Great you find a fix for you |
@smoke I completely understand the reasoning behind the change. But I don't understand why the Angular-CLI team did not provide a workaround (like an override option for example). We have 10 dependencies that rely on node modules ( I am very thankful to the Angular team to provide us an awesome framework with helpful tools (:heart:), but I spent many hours of my free time just to upgrade 1 element (Angular) of our application... and finally realize that we are at a dead end. Maybe going back to Angular CLI 1.7 is the best solution for now, but please think about developers that just want to upgrade their application without running into a wall :) |
My current (hacky) workaround is running this as a postinstall script:
In my case I don't use the node import that errors because my code only runs in a browser. So it can import the wrong package but who cares. This allows me to keep using the cli without ejecting webpack. It is of course a horrible, horrible hack. |
I have placed one good workaround in my post #10681 (comment) |
I've upgraded my application into Angularv6 and rxjsv6 succesfully.
I execute:
And the application compiles. When rendering the app on browser the first error is:
Which I fix by adding: (window as any).global = window; in polyfills.ts file.
And now I don't know how to proceed... |
works for me on renderer side without any other modifications (angular5/6). |
Why are people patching node_modules? This can be solved using tsconfig paths instead. Please see my PR to PeerTube for an example: Chocobozzz/PeerTube#742 EDIT: OK this has problems with the final build, even though it works for dev build :- |
Thanks @rezonant , that fixed it for me. I don't like patching
Then, in a
|
I'm sorry to say that we do not have support for the Electron platform currently in Angular CLI. We only support building browser apps, and while building browser apps the node native imports (like |
We do not need support for Electron. We only need the compiler to not fail when we include libraries which have been badly written to require fs for some marginal functionality which we wont be using from them. When you started enforcing this in 6 you made a serious breaking change which could be easily avoided if you allowed us to go around this and avoid the compiler error. |
@filipesilva isn't the CLI supposed to support angular universal, which could use the same node APIs that electron uses? |
Just found this https://github.com/angular-guru/electron-builder (not tested but looks great) |
Here's my workaround, works both in |
Try ngx-electron. It solved issues like this for me. |
how imported handlebarjs.js in angular.json |
I have the same issue in my React-Redux project.I have use npm install "fs".But when I import * as fs from 'fs',there's a error.... |
I create a new angular project: ng new ngapp1. now, I modify the file : app.component.ts, add some code then I process the cmd: ng serve, I get a isssue: I think it's a simple issue.but i don't know how to fix it. and i find many people have the same question. |
I struggled with this problem for a long time. But I believe the best way to get around this error once and for all is to use a custom webpack build. I'm using this angular-builder to add the custom webpack config. After adding the builder, if you're targeting electron you can do something like this:- module.exports = {
...
output: {
globalObject: 'self',
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
target: 'electron-renderer'
} If you're targeting web, you can do something like this:- module.exports = {
...
target: 'web',
node: { fs: 'empty' }
} This is not a perfect config, but once you add webpack to the build process, the world opens up to you for your specific use cases. Simply move to stack overflow to find an answer. I've tested this builder with angular version 6, 7, 8 without any problems. |
Update: Solved with help from SO Answer |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Versions
Repro steps
When I develop an electron app (and thus have access to Node's
fs
module), I can't access node modules because typescript or webpack isn't able to resolve it.Observed behavior
I get an error while building the application
ng build
:Desired behavior
I'd like to be able to use Node's modules and define somewhere in the angular.json configuration to allow certain modules (in other words: exclude them from the build process, as the Node runtime provides that stuff).
Mention any other details that might be useful (optional)
In Angular 5 I was able to
eject
and add in thewebpack.config.js
following lines at the root level:However since Anuglar 6 does not provide an eject anymore, I'm not able to use that old webpack.config.json from v5 anymore. To make Angular 6 workable in Electron I need to be able to use a webpack.config.js again or maybe a config option in angular.json that allows me to define webpack's
externals
.The text was updated successfully, but these errors were encountered: