-
-
Notifications
You must be signed in to change notification settings - Fork 516
Accessing Node core modules from within an Aurelia Electron App #537
Comments
import * as fs from 'fs'; Also, you might need to configure JSPM to declare 'fs' as external. Not sure how that's done with JSPM. You also need to enable nodeIntegration with Electron too. |
In the past, I actually wrote a custom loader for jspm like this: System.set('npm', System.newModule({
'fetch': function(load, fetch) {
var id = load.name.substring(0, load.name.indexOf('!'));
load.metadata.requiredModule = require(id);
return '';
},
'instantiate':function(load) {
return load.metadata.requiredModule;
}
})); I just put this code in my import * as fs from 'fs!npm'; |
The problem with your approach Rob is lack of TS typing in such a case. One
|
Sure, of course...he wasn't asking about Webpack though. The above solution works fine for SystemJS. There may be another way to handle it with SystemJS, I'm not sure. I would ask the SystemJS team about that. It certainly would be better if there was a way to tell it to use the native require for certain modules. I'd like to know the answer to that myself. |
That would be great. Accessing the file system would be a great example for the Aurelia/Electron skeleton since that is probably the first thing you would want to do in a desktop app :) |
Discussed in this issue. "If you're referring to the original question, Node core modules can now be imported with import {readFile} from '@node/fs', but that will only work in Node environments of course." That did not work for me though :( |
This is also maybe something to consider with regards to the Aurelia CLI. |
FYI, I just tried the solution suggested by @EisenbergEffect JSPM version 0.16.39
Further help on this issue would be much appreciated |
One step closer to success.
This actually works at runtime, but vs code is not able to figure out the module so that means no intellisense. Anybody knows how to trick typescript/vscode into resolving '@node/fs' ? |
@seesharper here's how you can do it: microsoft/TypeScript#6615 |
Nice, I will check it out |
I can't figure out exactly what I need to do here. Could you point me in the right direction with an example? |
If all you need is 'fs' you can just create an alias for it.
declare module "@node/fs" {
import * as fs from 'fs';
export = fs;
} this should work even with TS 1.8. You'll obviously need the typings for node for this to work. |
Worked like a charm. Thanks a lot for your help!!!! |
@niieani TypeScript 2.0 goes away from notion of typings, they've introduced types that are installed via |
On the other hand I've found a workaround for the above problem, it seems that you can kind of "map"
|
@lu4 cool workaround. Note that the notion of typings does not go away as you stated. What changes is the tooling for installing typings - in favor of NPM in the |
Thanks, yeah probably that's a better way to express the change... :) |
I'm struggling with the same problem, but none of the solutions above have worked for me. I have mapped fs to "@node/fs" in my Systemjs config file, but I get this error when trying to use "fs" in my app:
|
@mskutle try: Assuming you have the following in your System JS config:
Then use require rather than import in your js/ts file:
HTH. |
I am doing a little experiment with using Aurelia to build Electron applications.
You can find what I have got so far here.
https://github.com/seesharper/AureliaElectronHappiness
The question is how do I access core modules such as "fs" from within a typescript component?
I have tried this
VS Code does give the impression that this is okay since it provides the intellisense for the fs object, but at runtime this failes with an error.
Is it even possible to do this somehow?
The text was updated successfully, but these errors were encountered: