Closed kamira closed 6 years ago
Kibana looks like they have quite an extensive dependency system on top of just package.json. I'd file the issue there. puppeteer-core
definitely depends on ws
and it should be installed when you add it.
I am having the same issue,
But I am not sure I understand what the fix was?
I ran this, but it did not change anything.
npm install --save ws
What was done to solve the OP problem?
@AirborneEagle this seems to be a downstream issue, please file a bug to kibana
I am confused. I am not using Kibana. I am using puppeteer in my own application. More specifically I am using pdf-puppeteer. https://github.com/westmonroe/pdf-puppeteer#readme
Did this ever get resolved? I am getting the same error, either if I use puppeteer or puppeteer-core I am using inside Electron if that makes any difference but it shouldn't.
Help ?
Did this ever get resolved? I am getting the same error, either if I use puppeteer or puppeteer-core I am using inside Electron if that makes any difference but it shouldn't.
Help ?
It happened to me when I accidentally tried to ran puppeteer from inside a browser code. If that's your case by any chance.
@tomermes Yea it's similar. Electron acts like a browser in many ways, because it uses Chromium etc under the hood.
Tried looking around and it seems that you can not use Puppeteer inside Electron :disappointed:
Tried looking around and it seems that you can not use Puppeteer inside Electron
@AnthoniG Electron has a lot of powerful APIs on its own. Why would you want to?
I am getting the same error while compiling.
ERROR in ./node_modules/puppeteer/lib/WebSocketTransport.js
Module not found: Error: Can't resolve 'ws' in 'c:\...\project\node_modules\puppeteer\lib'
How to fix this? I checked the path, it exist.
@aslushnikov Electron is very powerful yes. However in order to automate scraping simple websites I have to use IPC and it gets very messy very quickly.
Using puppeteer sandbox I could do it in a few less lines and there was no messing about with IPC at all. So having this inside Electron, or if there's anything similar you might now, would be absolutely great.
I am getting the same error while compiling.
ERROR in ./node_modules/puppeteer/lib/WebSocketTransport.js Module not found: Error: Can't resolve 'ws' in 'c:\...\project\node_modules\puppeteer\lib'
How to fix this? I checked the path, it exist.
I also tried the same bug when i used to webpack it does not work for me
Having the same trouble. I want to run puppeteer in the context of the electron. So when I run script with pupeeter scraping like node test.js
its working. But when I require it inside the electron app to be able to run this script on button click from within electron app I get
./node_modules/puppeteer-core/lib/WebSocketTransport.js
Module not found: Can't resolve 'ws' in .....
Guys, if you're attempting to use it from the create-react-app bundle, then it's not going to work. According to their npm page:
https://www.npmjs.com/package/ws
Note:
This module does not work in the browser. The client in the docs is a reference to a back end with the role of a client in the WebSocket communication. Browser clients must use the native WebSocket object. To make the same code work seamlessly on Node.js and the browser, you can use one of the many wrappers available on npm, like isomorphic-ws.
Also, for bundling Puppeteer for browser use, see https://github.com/GoogleChrome/puppeteer/blob/master/utils/browser/README.md
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = {
// ...
externals: {
puppeteer: 'require("puppeteer")',
// ...
},
};
Wrapping it in require()
is important because puppeteer doesn't have a global export like jQuery and React do.
@dfoverdx +1 for your solution. I was using webpack too (it's not a web application tho, it's just running on node) and it definitely worked for me.
My initial error output was as follows:
$ webpack && node dist/bundle.js
Hash: 1b2fd47f36807b1b273d
Version: webpack 4.38.0
Time: 1573ms
Built at: 07/28/2019 10:10:40 PM
Asset Size Chunks Chunk Names
bundle.js 1.53 MiB main [emitted] main
Entrypoint main = bundle.js
[0] fs (ignored) 15 bytes {main} [built]
[1] ./BrowserFetcher (ignored) 15 bytes {main} [built]
[2] util (ignored) 15 bytes {main} [built]
[3] util (ignored) 15 bytes {main} [built]
[4] rimraf (ignored) 15 bytes {main} [built]
[5] child_process (ignored) 15 bytes {main} [built]
[6] readline (ignored) 15 bytes {main} [built]
[7] ./node6/lib/Puppeteer (ignored) 15 bytes {main} [built]
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {main} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {main} [built]
[./src/index.ts] 3.25 KiB {main} [built]
+ 78 hidden modules
ERROR in ./node_modules/puppeteer/lib/WebSocketTransport.js
Module not found: Error: Can't resolve 'ws' in '/Users/jm/Documents/Joel/scraper/node_modules/puppeteer/lib'
@ ./node_modules/puppeteer/lib/WebSocketTransport.js 16:18-31
@ ./node_modules/puppeteer/lib/Launcher.js
@ ./node_modules/puppeteer/lib/Puppeteer.js
@ ./node_modules/puppeteer/index.js
@ ./src/index.ts
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
But when I just added
externals: {
puppeteer: 'require("puppeteer")',
// ...
},
to webpack config, it worked like a charm:
$ webpack && node dist/bundle.js
Hash: 1bd4c72ee57858351a97
Version: webpack 4.38.0
Time: 1117ms
Built at: 07/28/2019 10:26:41 PM
Asset Size Chunks Chunk Names
bundle.js 17.7 KiB main [emitted] main
Entrypoint main = bundle.js
[./src/index.ts] 3.25 KiB {main} [built]
[puppeteer] external "require(\"puppeteer\")" 42 bytes {main} [built]
✨ Done in 5.34s.
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.
Can anyone tell me where to add this config?
@shubuu97
Inside webpack.config.js
. Here's my config as an example:
const path = require('path');
module.exports = {
entry: './src/index.ts',
devtool: 'inline-source-map',
mode: 'development',
// the webpack config just works
// SEE https://github.com/webpack/webpack/issues/1599
target: 'node',
node: {
__dirname: false,
__filename: false,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.ts$/,
loader: 'tslint-loader',
enforce: 'pre',
options: {
fix: true,
tsConfigFile: 'tsconfig.json',
},
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
externals: {
puppeteer: 'require("puppeteer")',
fs: 'require("fs")',
},
};
Do we need to do anything else after adding this because i'm still facing the same error
i got an error we require is not defined
i got an error we require is not defined
@kalimuthu123 what environment are you running it in? My solution was for use in Node. Browsers would not have require
defined.
I know I saw documentation once for running it in the browser, but I can't seem to find it now. Since you don't need to download Chromium for use in the browser, you should use puppeteer-core
.
@dfoverdx I followed the guide for building puppeteer-web.js
I have this code inside background.js file
const puppeteer = require('puppeteer');
console.log(puppeteer);
I am getting
Uncaught ReferenceError: puppeteer is not defined
Any resolution to this? Ive tried all these solutions but still get the Can't resolve 'ws'
@dfoverdx I followed the guide for building puppeteer-web.js
I have this code inside background.js file
const puppeteer = require('puppeteer'); console.log(puppeteer);
I am getting
Uncaught ReferenceError: puppeteer is not defined
Do you install puppeteer first? It is ok which I test from Repl.it .
这个是webpack include 的问题,可以把test文件写到src外面,并修该package.js 的jest配置项即可
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.
+1 for your solution save my life
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.
it's helpful for me. Thanks for u.
how do i fix this problem if Im using react-native?
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.
thx, you just save my ass
Where the hell is my fucking best friend
On Mon, Nov 9, 2020 at 1:03 AM Zoffy Zhang notifications@github.com wrote:
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... },};
Wrapping it in require() is important because puppeteer doesn't have a global export like jQuery and React do.
thx, you just save my ass
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/puppeteer/puppeteer/issues/3466#issuecomment-723806667, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARGBR2JXFKRDXIJMDR4LUN3SO6H5DANCNFSM4GAE743Q .
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do.Can anyone tell me where to add this config?
For me, this happened when bundling with webpack, intending the bundle to be used in node. The trick was to set puppeteer as an external.
const config = { // ... externals: { puppeteer: 'require("puppeteer")', // ... }, };
Wrapping it in
require()
is important because puppeteer doesn't have a global export like jQuery and React do. after using this config, web throw an error
@tomermes Yea it's similar. Electron acts like a browser in many ways, because it uses Chromium etc under the hood.
Tried looking around and it seems that you can not use Puppeteer inside Electron 😞
Each Electron app has a single main process, which acts as the application's entry point. The main process runs in a Node. js environment, meaning it has the ability to require modules and use all of Node. js APIs.
If scripts run in electron main
process, it's a nodejs environment not browser enivronment,can use fs
API etc..., but why still thow this error ?
(Note. call puppeter.launch()
the chrome.exe can started, but throw error )
ws does not work in the browser. Browser clients must use the native WebSocket object
What steps will reproduce the problem?
What is the expected result?
I should Pass and kibana will be running
What happens instead?
I got Module not found error message.
Error Message: