Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Issue with NPM dependencies which require('fs'); #95

Closed
joserobjr opened this issue Aug 23, 2018 · 2 comments
Closed

Issue with NPM dependencies which require('fs'); #95

joserobjr opened this issue Aug 23, 2018 · 2 comments

Comments

@joserobjr
Copy link

When I try to add dependency to windows-cpu as in:

kotlinFrontend {
    npm {
        dependency "windows-cpu"
        devDependency "karma"     // development dependency
    }

    webpackBundle {
        bundleName = "main"
    }

The bundle task fails:

> Task :parent-projects:webpack-bundle FAILED
path-to-project\build\node_modules\windows-cpu'
 @ C:/path-to-project/build/node_modules/windows-cpu/index.js 9:11-24
 @ ./node-manager.js

The 9:11-24 is highlighting this method invocation:

require('fs')

It does not happens to the other requirements.

I googled about it and found this issue with webpack:
webpack-contrib/css-loader#447

It suggests us to add:

node: {
  fs: 'empty'
}

And recent messages suggests to add --config:
webpack-contrib/css-loader#447 (comment)

How can I achieve that with kotlin-frontend-plugin?

@joserobjr
Copy link
Author

I found a solution:
pugjs/pug-loader#8 (comment)

To apply this configuration I had to create a directory named webpack.config.d next to the src directory (similarly to how it's done in this example) and place a javascript there with any name containing this line:

config.target = 'async-node';

@joserobjr
Copy link
Author

By the way,

I also managed to add:

node: {
  fs: 'empty'
}

to the config by using the lines below inside the webpack.config.d directory:

config.node = {
  fs: 'empty'
}

But that just caused the module to load an empty module. It's functions and classes were not available. So I don't recommend doing it.

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

No branches or pull requests

1 participant