I'm trying to use the node puppeteer library in a Chrome extension. I'm using the extension-cli build tool, which uses webpack under the hood, but when I try to build I get errors regarding multiple missing modules such as:
Error in plugin "webpack-stream"
Message:
Module not found: Error: Can't resolve 'fs' in '/path/to/my/project/node_modules/chownr'
Module not found: Error: Can't resolve 'path' in '/path/to/my/project/node_modules/chownr'
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: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
I understand the reason for the errors and I have installed all 11 related core node packages that are affected. I've also created the following webpack.config.js file in my project root directory (alongside the node_modules dir) with the following:
module.exports = {
resolve: {
fallback: {
"path": require.resolve("path-browserify"),
"assert": require.resolve("assert/"),
"constants": require.resolve("constants-browserify"),
"crypto": require.resolve("crypto-browserify"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"os": require.resolve("os-browserify/browser"),
"stream": require.resolve("stream-browserify"),
"url": require.resolve("url/"),
"util": require.resolve("util/"),
"zlib": require.resolve("browserify-zlib"),
}
}
}
I'm still getting the exact same errors during the build though. Do I have to put the config above somewhere else?