parallel.js icon indicating copy to clipboard operation
parallel.js copied to clipboard

Getting an error "Can't resolve 'os'"

Open dagumak opened this issue 2 years ago • 1 comments

I am using node v16.13.0 and Gatsby. This is what happens after I install parallel.js and imported it in my code. I am not really sure what the issue is.

import Parallel from 'paralleljs';

const p = new Parallel([0, 1, 2, 3, 4, 5, 6]);
const log = function () { console.log(arguments); };
 ERROR #98124  WEBPACK

Generating development JavaScript bundle failed

Can't resolve 'os' in '/Users/hello/projects/example/yoyo/app/node_modules/paralleljs/lib'

If you're trying to use a package make sure that 'os' is installed. If you're trying to use a local file make sure that the path is correct.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
	- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "os": false }

File: node_modules/paralleljs/lib/parallel.js:81:8

dagumak avatar Jan 04 '22 11:01 dagumak

Not sure if that helps, but you can try installing this pollyfill.

run npm install node-polyfill-webpack-plugin

then add the following to your config

const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin()
	]
};

Ahmed-ShawkyEgy avatar Jul 28 '22 11:07 Ahmed-ShawkyEgy