puppeteer: Problem with WebSocketTransport.js
- Puppeteer version: v1.10.0
- Platform / OS version: Windows 7 (x64)
- Node.js version: v10.13.0
- install a puppeteer in the project
- try to run a project (npm run serve)
- an error:
This dependency was not found:
* ws in ./node_modules/puppeteer/lib/WebSocketTransport.js
To install it, you can run: npm install --save ws
in fact, this dependence is established.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 10
- Comments: 28 (2 by maintainers)
正常使用puppeteer是完全没有问题的,但是当我在使用vue-cli3创建的项目中使用puppeteer的时候,就会提示这个错误。我同样运行了npm install --save ws 这个命令,但是依旧不起作用。
I have the same issue. I run
jest __integration__/my.spec.js
with the dummy test file below :my.spec.js
The result is :
Looking at the file
node_modules/puppeteer/package.json
, I see there is a"browser"
entry, as below :Two observations from that :
"browser"
entry, (or just of the"ws"
entry within it), makes the import work. However I have no idea why this influence noderequire()
behavior. As I understand it, this field should only be used by bundlers, like Webpack, when targetting a browser environment."./utils/browser/WebSocket"
provided as a replacement forws
in case of a browser environment, since there is no such file in the puppeteer package.As a temporary solution, I reverted to version
~1.8.0
of puppeteer, before the introduction of that"browser"
field.inside your project
node_modules/puppeteer/lib/WebSocketTransport.js
need to change: fromconst WebSocket = require('ws');
toconst WebSocket = require('../node_modules/ws/index');
@1254859753 使用npm正常安装好ws依赖之后,删除node_modules/puppeteer/package.json中的这一行就可以正常运行了
@bobbybobby Please read utils/browser/README.md.
I’m having the same problem. inside my project node_modules/puppeteer/lib/WebSocketTransport.js I change: const WebSocket = require(‘ws’); to const WebSocket = require(‘…/node_modules/ws/index’); but now I have another error : TypeError: BrowserFetcher is not a constructor at resolveExecutablePath (node_modules/puppeteer/lib/Launcher.js:688:28) at ChromeLauncher.launch (node_modules/puppeteer/lib/Launcher.js:198:53)