Closed davidlinketech closed 3 years ago
PS: I'm really new to Github, so sorry if the Question doesn't look that nice :/
The code you're trying to run in TypeScript, not JS/ES. You need to change the import statements to require()
.
Oh forgot to close this by myself, but for those who are interested, this is what I have now:
const puppeteer = require('puppeteer-extra') const StealthPlugin = require('puppeteer-extra-plugin-stealth') puppeteer.use(StealthPlugin()) const ghostCursor = require('ghost-cursor')
const run = async (url) => { const selector = '#keepMeLoggedIn' const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage() const cursor = await ghostCursor.createCursor(page); await page.goto(url) await page.waitForSelector(selector) await cursor.click(selector) // shorthand for // await cursor.move(selector) // await cursor.click() }
run('https://www.nike.com/de/login');
Im trying to run this code: `import { createCursor } from "ghost-cursor" import puppeteer from "puppeteer"
const run = async (url) => { const selector = "#sign-up button" const browser = await puppeteer.launch({ headless: false }); const page = browser.newPage() const cursor = createCursor(page) await page.goto(url) await page.waitForSelector(selector) await cursor.click(selector) // shorthand for // await cursor.move(selector) // await cursor.click() }
run(https://www.nike.com/de/login);`
But I'm getting this error the whole time:
(node:3984) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use
node --trace-warnings ...` to show where the warning was created) C:\Users\David\Desktop\learn_js-Kopie.js:1 import { createCursor } from "ghost-cursor" ^^^^^^SyntaxError: Cannot use import statement outside a module at wrapSafe (internal/modules/cjs/loader.js:1001:16) at Module._compile (internal/modules/cjs/loader.js:1049:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47 `