Open lijingmu opened 1 year ago
Finally I use scripts to bundle them, it works well now.
1. add post build in NPM script
"build": "webpack --config ./webpack.prod.config.js && node prepare-package.js postBuild",
2. copy files from node_modules to output directory after build in prepare-package.js
const postBuild = async () => {
await cpvm2("bridge.js");
await cpvm2("events.js");
await cpvm2("setup-sandbox.js");
await cpvm2("setup-node-sandbox.js");
};
3. add them in package.json files property to bundle them
Seems like this is causing all Puppeteer bundled scripts to fail as well (eg. bundling with esbuild
):
@patriksimek any idea what could be causing this?
Oh it seems like vm2
has been incompatible with bundling for years, hope the approach of using fs.readFileSync()
and similar to read files inside of node_modules
on runtime can be reconsidered 🤞
I use webpack to create a bundle, vm2 is one dependency. webpack can work well with following config:
when I run the project I encountered:
I think it is because below:
I have to copy these files to dist. Any suggestions or workaround? Thanks