Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_INVALID_ARG_TYPE error while trying single run #5

Closed
bux opened this issue Feb 21, 2022 · 6 comments · Fixed by #4
Closed

ERR_INVALID_ARG_TYPE error while trying single run #5

bux opened this issue Feb 21, 2022 · 6 comments · Fixed by #4

Comments

@bux
Copy link

bux commented Feb 21, 2022

OS: Windows 10
node js: v16.13.2

I'm getting the following error when trying pnpm dlx unlighthouse --site https://unlighthouse.dev/guide/

√ Successfully connected to https://unlighthouse.dev/guide/, status code: 200.                                                                unlighthouse 15:51:16
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at readFile (node:fs:393:10)
    at go$readFile (C:\Users\jo\AppData\Local\Temp\dlx-7572\5\node_modules\.pnpm\[email protected]\node_modules\graceful-fs\graceful-fs.js:118:14)
    at Object.readFile (C:\Users\jo\AppData\Local\Temp\dlx-7572\5\node_modules\.pnpm\[email protected]\node_modules\graceful-fs\graceful-fs.js:115:12)
    at C:\Users\jo\AppData\Local\Temp\dlx-7572\5\node_modules\.pnpm\[email protected]\node_modules\universalify\index.js:8:12
    at new Promise (<anonymous>)
    at Object.readFile (C:\Users\jo\AppData\Local\Temp\dlx-7572\5\node_modules\.pnpm\[email protected]\node_modules\universalify\index.js:7:14)
    at generateClient (file:https:///C:/Users/jo/AppData/Local/Temp/dlx-7572/5/node_modules/.pnpm/@[email protected]/node_modules/@unlighthouse/core/dist/index.mjs:906:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.ctx.setServerContext (file:https:///C:/Users/jo/AppData/Local/Temp/dlx-7572/5/node_modules/.pnpm/@[email protected]/node_modules/@unlighthouse/core/dist/index.mjs:1228:5)
    at async run (file:https:///C:/Users/jo/AppData/Local/Temp/dlx-7572/5/node_modules/.pnpm/@[email protected]/node_modules/@unlighthouse/cli/dist/cli.mjs:27:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}
 ERROR  Command failed with exit code 1: C:\Users\jo\AppData\Local\Temp\dlx-7572\unlighthouse.CMD --site https://unlighthouse.dev/guide/
@bux bux changed the title Error while trying this out ERR_INVALID_ARG_TYPE error while trying this out Feb 21, 2022
@bux bux changed the title ERR_INVALID_ARG_TYPE error while trying this out ERR_INVALID_ARG_TYPE error while trying single run Feb 21, 2022
@thomasbnt
Copy link

thomasbnt commented Feb 21, 2022

Same error with

npx unlighthouse --site unlighthouse.dev --debug

> npx unlighthouse --site unlighthouse.dev --debug
» Starting Unlighthouse at root: ---
» Discovered config definition {                                                                                                                                   unlighthouse 19:51:48
  config: undefined,                                                                                                                                                                    
  sources: []                                                                                                                                                                           
}                                                                                                                                                                                       
» Post config resolution {                                                                                                                                         unlighthouse 19:51:48
  routerPrefix: '',                                                                                                                                                                     
  apiPrefix: '/api',                                                                                                                                                                    
  cache: true,                                                                                                                                                                          
  client: {
    groupRoutesKey: 'route.definition.name',
    columns: {
      overview: [Array],
      performance: [Array],
      accessibility: [Array],
      'best-practices': [Array],
      seo: [Array]
    }
  },
  scanner: {
    customSampling: {},
    ignoreI18nPages: true,
    maxRoutes: 200,
    skipJavascript: true,
    samples: 1,
    throttle: false,
    crawler: true,
    dynamicSampling: 5,
    sitemap: true,
    device: 'mobile'
  },
  server: {
    port: 5678,
    showURL: false,
    open: true
  },
  discovery: {
    supportedExtensions: [
      'vue',
      'md'
    ],
    pagesDir: 'pages'
  },
  root: '-',
  outputPath: '.lighthouse',
  debug: true,
  puppeteerOptions: {
    executablePath: '-'
  },
  puppeteerClusterOptions: {
    monitor: true,
    workerCreationDelay: 500,
    retryLimit: 3,
    timeout: 300000,
    maxConcurrency: 12,
    skipDuplicateUrls: false,
    retryDelay: 2000,
    concurrency: 3,
    puppeteer: PuppeteerNode {
      _changedProduct: false,
      _isPuppeteerCore: true,
      _projectRoot: '\nvm\\v16.6.0\\node_modules\\unlighthouse\\node_modules\\puppeteer-core',
      __productName: undefined,
      _preferredRevision: '961656'
    }
  },
  lighthouseOptions: {
    onlyCategories: [
      'performance',
      'accessibility',
      'best-practices',
      'seo'
    ],
    throttlingMethod: 'provided',
    throttling: {
      rttMs: 0,
      throughputKbps: 0,
      cpuSlowdownMultiplier: 1,
      requestLatencyMs: 0,
      downloadThroughputKbps: 0,
      uploadThroughputKbps: 0
    },
    formFactor: 'mobile',
    screenEmulation: {
      mobile: true
    }
  },
  urls: [],
  site: 'https://unlighthouse.dev/',
  hooks: {
    'resolved-config': [AsyncFunction: resolved-config]
  }
}
» Testing Site https://unlighthouse.dev/ is valid.                                                                                                                 unlighthouse 19:51:48  
√ Successfully connected to https://unlighthouse.dev/, status code: 200.                                                                                           unlighthouse 19:51:48
» Creating Unlighthouse                                                                                                                                            unlighthouse 19:51:48
» Setting Unlighthouse Site URL [Site: https://unlighthouse.dev/]                                                                                                  unlighthouse 19:51:48
» Setting Unlighthouse Server Context [Server: https://localhost:5678/]                                                                                             unlighthouse 19:51:48
» Using preset: @unrouted/[email protected]                                                                                                                unlighthouse-api 19:51:48  
» Using plugin: laravelNamedParams                                                                                                                             unlighthouse-api 19:51:48  
» Registering route GET /__lighthouse.                                                                                                                         unlighthouse-api 19:51:48  
» Registering route POST /api/reports/rescan.                                                                                                                  unlighthouse-api 19:51:48  
» Registering route GET,HEAD /api/reports/:id/lighthouse.                                                                                                      unlighthouse-api 19:51:48  
» Registering route GET,HEAD /api/reports/:id/full-page-screenshot.                                                                                            unlighthouse-api 19:51:48  
» Registering route POST /api/reports/:id/rescan.                                                                                                              unlighthouse-api 19:51:48  
» Registering route GET,HEAD /api/__launch.                                                                                                                    unlighthouse-api 19:51:48  
» Registering route GET,HEAD /api/ws.                                                                                                                          unlighthouse-api 19:51:48  
» Registering route GET,HEAD /api/reports.                                                                                                                     unlighthouse-api 19:51:48
» Registering route GET,HEAD /api/reports/:id.                                                                                                                 unlighthouse-api 19:51:48  
» Registering route GET,HEAD /api/scan-meta.                                                                                                                   unlighthouse-api 19:51:48  
» Registering route GET /**.                                                                                                                                   unlighthouse-api 19:51:48  
» Registering route GET /.                                                                                                                                     unlighthouse-api 19:51:48  
» Setting up 12 routes.                                                                                                                                        unlighthouse-api 19:51:48  
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined

@harlan-zw harlan-zw linked a pull request Feb 22, 2022 that will close this issue
@harlan-zw
Copy link
Owner

harlan-zw commented Feb 22, 2022

Hey @bux & @thomasbnt

Thanks for reporting this issue. Looks like it was a bug with Windows.

I've pushed up a fix and it seems to be working.

Would you mind trying again with the command

pnpm dlx unlighthouse@latest --site https://unlighthouse.dev

or

npx unlighthouse@latest --site unlighthouse.dev --debug

@bux
Copy link
Author

bux commented Feb 22, 2022

@harlan-zw Yeah, that looks good. Thank you for the fast fix :)

@not-nemlig
Copy link

I just got the same issue today, trying it out. I run on a mac.

› Starting Unlighthouse at root: /Users/nickiskipper cwd: /Users/nickiskipper                                                                            unlighthouse 07:00:44
› Discovered config definition {                                                                                                                         unlighthouse 07:00:44
  config: undefined,
  sources: []
}
› Unable to locale page files, disabling route discovery.                                                                                                unlighthouse 07:00:44
› Found chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome.                                                                          unlighthouse 07:00:44
› Post config resolution {                                                                                                                               unlighthouse 07:00:44
  routerPrefix: '/',
  apiPrefix: '/api',
  cache: true,
  client: {
    groupRoutesKey: 'route.definition.name',
    columns: {
      overview: [Array],
      performance: [Array],
      accessibility: [Array],
      'best-practices': [Array],
      seo: [Array]
    }
  },
  scanner: {
    customSampling: {},
    ignoreI18nPages: true,
    maxRoutes: 200,
    skipJavascript: true,
    samples: 1,
    throttle: false,
    crawler: true,
    dynamicSampling: 5,
    sitemap: true,
    device: 'mobile'
  },
  server: {
    port: 5678,
    showURL: false,
    open: true
  },
  discovery: false,
  root: '/Users/nickiskipper',
  outputPath: '.unlighthouse',
  debug: true,
  puppeteerOptions: {
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    defaultViewport: {
      width: 360,
      height: 640
    }
  },
  puppeteerClusterOptions: {
    monitor: true,
    workerCreationDelay: 500,
    retryLimit: 3,
    timeout: 300000,
    maxConcurrency: 8,
    skipDuplicateUrls: false,
    retryDelay: 2000,
    concurrency: 3,
    puppeteer: PuppeteerNode {
      _changedProduct: false,
      _isPuppeteerCore: true,
      connect: [Function: bound bound connect],
      configuration: [Object],
      defaultBrowserRevision: '1108766',
      launch: [Function: bound launch],
      executablePath: [Function: bound executablePath],
      defaultArgs: [Function: bound defaultArgs],
      createBrowserFetcher: [Function: bound createBrowserFetcher]
    }
  },
  lighthouseOptions: {
    onlyCategories: [
      'performance',
      'accessibility',
      'best-practices',
      'seo'
    ],
    throttlingMethod: 'provided',
    throttling: {
      rttMs: 0,
      throughputKbps: 0,
      cpuSlowdownMultiplier: 1,
      requestLatencyMs: 0,
      downloadThroughputKbps: 0,
      uploadThroughputKbps: 0
    },
    formFactor: 'mobile',
    screenEmulation: {
      mobile: true,
      width: 360,
      height: 640,
      deviceScaleFactor: 2
    }
  },
  urls: [],
  site: 'https://nemlig.com/',
  hooks: {
    'resolved-config': [AsyncFunction: resolved-config]
  }
}
› Testing Site https://nemlig.com/ is valid.                                                                                                             unlighthouse 07:00:44
✔ Request to site https://nemlig.com/ redirected to https://www.nemlig.com/, using that as the site.                                                     unlighthouse 07:00:45
› Creating Unlighthouse                                                                                                                                  unlighthouse 07:00:45
› Setting Unlighthouse Site URL [Site: https://www.nemlig.com/]                                                                                          unlighthouse 07:00:45
› Setting Unlighthouse Server Context [Server: https://localhost:5678/]                                                                                   unlighthouse 07:00:45
› Creating new Unrouted ctx: unlighthouse-api {                                                                                                      unlighthouse-api 07:00:45
  debug: true,
  prefix: '/',
  middleware: [],
  hooks: {
    'serve:before-route': [Function: serve:before-route]
  },
  plugins: [
    {
      meta: [Object],
      setup: [AsyncFunction: setup]
    }
  ],
  presets: [
    {
      meta: [Object],
      setup: [AsyncFunction: setup]
    },
    {
      meta: [Object],
      setup: [AsyncFunction: setup]
    }
  ],
  name: 'unlighthouse-api',
  app: {
    use: [Function: use],
    handler: [AsyncFunction (anonymous)] {
      __is_handler__: true
    },
    stack: [],
    options: {}
  }
}
› Using preset: @unrouted/[email protected]                                                                                                           unlighthouse-api 07:00:45
› Using preset: @unrouted/[email protected]                                                                                                          unlighthouse-api 07:00:45
› Using plugin: lazyRouteHandles                                                                                                                     unlighthouse-api 07:00:45
› Registering route get /__lighthouse.                                                                                                               unlighthouse-api 07:00:45
› Registering route post /api/reports/rescan.                                                                                                        unlighthouse-api 07:00:45
› Registering route post /api/reports/:id/rescan.                                                                                                    unlighthouse-api 07:00:45
› Registering route get,head /api/__launch.                                                                                                          unlighthouse-api 07:00:45
› Registering route get,head /api/ws.                                                                                                                unlighthouse-api 07:00:45
› Registering route get,head /api/reports.                                                                                                           unlighthouse-api 07:00:45
› Registering route get,head /api/scan-meta.                                                                                                         unlighthouse-api 07:00:45
› Registering route get /**.                                                                                                                         unlighthouse-api 07:00:45
› Registering route get /.                                                                                                                           unlighthouse-api 07:00:45
› Setting up 9 routes.                                                                                                                               unlighthouse-api 07:00:45
› Starting Unlighthouse [Server: https://localhost:5678/ Site: https://www.nemlig.com/ Debug: true]                                                       unlighthouse 07:00:45
› Attempting to fetch sitemap at https://www.nemlig.com/sitemap.xml                                                                                      unlighthouse 07:00:45
Error occurred during "crawl('https://www.nemlig.com/sitemap.xml')":
 Error: HTTP Error occurred: Response code 404 (Not Found)
› Fetched sitemap with 0 URLs.                                                                                                                           unlighthouse 07:00:45
ℹ Sitemap appears to be missing, falling back to crawler mode.                                                                                           unlighthouse 07:00:45
› Route has been queued. Path: / Name: _index.                                                                                                           unlighthouse 07:00:45

   ╭─────────────────────────────────────────╮
   │                                         │
   │   ⛵  unlighthouse cli @ v0.5.1         │
   │                                         │
   │   ▸ Scanning: https://www.nemlig.com/   │
   │   ▸ Route Discovery: Crawler            │
   │                                         │
   │   Root: /Users/nickiskipper             │
   │   URL: https://localhost:5678/           │
   │                                         │
   ╰─────────────────────────────────────────╯


  Puppeteer old Headless deprecation warning:
    In the near feature `headless: true` will default to the new Headless mode
    for Chrome instead of the old Headless implementation. For more
    information, please see https://developer.chrome.com/articles/new-headless/.
    Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
    If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.

› GET /favicon.ico 200 undefined - 0ms                                                                                                               unlighthouse-api 07:00:46
› GET /api/scan-meta 200 object - 0ms                                                                                                                unlighthouse-api 07:00:46
› GET /api/reports 200 object - 1ms                                                                                                                  unlighthouse-api 07:00:46
› HTML extract of https://www.nemlig.com/ took 918ms                                                                                                     unlighthouse 07:00:47
› Route has been queued. Path: / Name: _index.                                                                                                           unlighthouse 07:00:47
ℹ No internal links discovered on home page. Switching crawler to execute javascript.                                                                    unlighthouse 07:00:47
✔ Completed inspectHtmlTask for /. [Size: NaN undefined]                                                                                                 unlighthouse 07:00:47

  Puppeteer old Headless deprecation warning:
    In the near feature `headless: true` will default to the new Headless mode
    for Chrome instead of the old Headless implementation. For more
    information, please see https://developer.chrome.com/articles/new-headless/.
    Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
    If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object
    at Object.writeFileSync (node:fs:2239:5)
    at inspectHtmlTask (file:https:///Users/nickiskipper/.npm/_npx/9dcacbe7dba6f79c/node_modules/@unlighthouse/core/dist/index.mjs:645:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v18.15.0```

@mzaien
Copy link

mzaien commented May 9, 2023

pnpm dlx unlighthouse@latest --site https://unlighthouse.dev

Same here, I tired node 16/18/20 , npx/pnpx and nothing works

@camcnz
Copy link

camcnz commented May 9, 2023

This line is failing and needs a try catch and type check around it.

I changed it like this and it works.

if (resolvedConfig.cache && typeof html !== 'object'){
    try {
       fs.writeFileSync(htmlPayloadPath, html);
    } catch (error) {
      logger.error(`Failed to write HTML payload to cache: ${error}`);
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants