puppeteer: Can't found module ChromiumRevision building by webpack
- Puppeteer version: 1.2.0
- Platform / OS version: Windows 10
- Node.js version: 8.9.1
I use puppeteer in a production build, and I build my server by webpack, and there is a line of code:
node_modules\puppeteer\lib\Launcher.js
const ChromiumRevision = require(path.join(helper.projectRoot(),'package.json')).puppeteer.chromium_revision;
Inside projectRoot there is:
node_modules\puppeteer\lib\helper.js
static projectRoot() {
if (!projectRoot) {
// Project root will be different for node6-transpiled code.
projectRoot = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') :
path.join(__dirname, '..', '..');
}
return projectRoot;
}
Webpack has to resolve this path during building and put package.json
it in a separate module. But looks like it can’t do it, seems something wrong with __dirname
, option in webpack config node: __dirname: false/true
doesn’t help.
Is it ok to use puppeteer in build, like in one file: server.js? Is it ok to bundle puppeteer by webpack? Any workarounds?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 17 (4 by maintainers)
Commits related to this issue
- workaround for #2245 — committed to langfors/puppeteer by langfors 6 years ago
webpack.config.js
Ok guys, I’m on Mac OS and here the solution which I did and work in order to use pupperteer in one single file:
STEP 1: in
webpack.config.js
add this:STEP 2: Install those dependencies and update again your
webpack.config.js
according this stackoverflow commentSTEP 3:
sudo npm install -g puppeteer --unsafe-perm=true
It should works after 😃
I really don’t think that this is an issue that would be appreciated in the webpack issue tracker, though, since some of puppeteer’s code would be near-impossible to support for any bundler (e.g. dynamic requires).
But it’s also not strictly an issue with puppeteer.
I do believe that bundling is an important part of the Javascript ecosystem that any project should strive to support, however.
That being said, if you’re not afraid to override some of puppeteer’s code, here are the necessary changes to make it work with webpack:
In
node_modules/puppeteer/lib/Launcher.js
Change
into
(as pointed out by @kutsokon already)
In
node_modules/puppeteer/lib/BrowserFetcher.js
(in case you need this module)Change
into
Lastly, the required bits in the webpack configuration:
Evidently puppeteer accesses some functions dynamically as well and therefore doesn’t play nicely with
UglifyJS
. Keeping function names fixes some odd runtime issues, but I haven’t done the research where in puppeteer’s code one would have to make changes to address that.All of these changes were tested with
webpack@4
. Hope it helps! 😃Looks like the issue is with webpack; I’d try asking this on the webpack bugtracker.
Isn’t it better to replace
with this code?
@aengl @daveykane sure, let’s make pptr bundle’able. Moving this discussion over to #2119.
@131 I’m not sure I follow this.
Hi all ! Do you get a workaround for this one ? Can’t build a lambda with webpack including puppeteer…
@aengl suggested changes work, I think puppeteer could and should spend some time investigating this issue and look to put a fix / workaround in place.
How could this be closed ? We can’t bundle puppeteer (with browserify) for the same reasons - this is a major drawback.
A try/catch & fallback to a process.env.PUPPETEER_CHROMIUM_VERSION ( per puppeteer/install.js design ) would be perfect
Please file the issue downstream to WebPack repository and post a link here. This way all newcomers will know where to post concerns and further details.
@aslushnikov You still can help at least to highlighting this issue like unresolved and stay active discussion about that. Maybe someone find workaround or solution for this unresolved issue in this or another therd, or if webpack team fix it you can add solution to this opened thread to help other developers solve their problem. Also will be nice if you can link webpack issue with this thread. Does it make sense to you?
same problem here