Kesem David Kesem David - 8 months ago 64
Javascript Question

How to load Nodejs core modules using webpack

I'm having trouble loading the core modules of nodejs to the browser.


library depends on
which is a core module and loading my app produces
cannot find module "fs"

I've done some googling repeatedly ended up here - saying I should add
to my
file BUT, done as he suggested produces another error ->
process is not defined

I was wondering if there's any module-loader for that need? i couldnt find any.


module.exports = {
entry: "./app/boot",
output: {
path: __dirname,
filename: "./dist/bundle.js"
resolve: {
extensions: ['', '.js', '.ts']
module: {
loaders: [
{ test: /\.ts/, loaders: ["ts-loader"], exclude: /node_modules/ }
preLoaders: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ test: /\.js$/, loader: "source-map-loader", exclude: ['node_modules', 'ext-*', 'lib', 'tools'] }
debug: true,
devtool: 'source-map'

Any insights would be much apreciated, thanks in advance and please let me know if any other information would be helpful.

I'm not using

Answer Source

You can't.

There is no equivalent to fs that would work properly in the browser. JavaScript executed in a browser is running in a sandbox for security reasons and you have only very limited access to the client's file system, which is what the module fs is used for in NodeJS.