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

[Bug?]: 'TypeError: p.match is not a function' at Object.toPortablePath in .pnp.cjs #3783

Closed
1 task
unzico opened this issue Nov 23, 2021 · 3 comments · Fixed by #3889
Closed
1 task

[Bug?]: 'TypeError: p.match is not a function' at Object.toPortablePath in .pnp.cjs #3783

unzico opened this issue Nov 23, 2021 · 3 comments · Fixed by #3889
Assignees
Labels
bug Something isn't working upholded Real issues without formal reproduction

Comments

@unzico
Copy link

unzico commented Nov 23, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

I've tried to generate a PDF using puppeteer. However, this didn't work as yarn threw an error. This seems to be related to the file urls, as this issue only occurs when I call puppeteer's pdf method to generate and save the file.

I've found similar issues with different use cases:

I've tried both yarn v2 and yarn v3 (latest version) without any change to the outcome.

To reproduce

Repo: https://github.com/unzico/yarn2-puppeteer-pdf

  1. git clone this project
  2. cd into this project
  3. yarn && yarn build to install deps and build files
  4. yarn start

Running yarn start should log the following error message:

TypeError: p.match is not a function
  at Object.toPortablePath (D:\[...]\yarn2-puppeteer-pdf\.pnp.cjs:6092:35)
  at PosixFS.mapToBase (D:\[...]\yarn2-puppeteer-pdf\.pnp.cjs:12033:24)
  at PosixFS.fsMapToBase (D:\[...]\yarn2-puppeteer-pdf\.pnp.cjs:8097:25)
  at PosixFS.writeFilePromise (D:\[...]\yarn2-puppeteer-pdf\.pnp.cjs:7937:18)
  at URLFS.writeFilePromise (D:\[...]\yarn2-puppeteer-pdf\.pnp.cjs:7936:30)
  at Object.getReadableAsBuffer (D:\[...]\yarn2-puppeteer-pdf\build\index.js:2258:29)
  at processTicksAndRejections (internal/process/task_queues.js:97:5)
  at async Page.pdf (D:\[...]\yarn2-puppeteer-pdf\build\index.js:7424:16)
  at async printPdf (D:\[...]\yarn2-puppeteer-pdf\build\index.js:25371:3)
  at async main (D:\[...]\yarn2-puppeteer-pdf\build\index.js:25381:5)

The parameter p passed to Object.toPortablePath has the following value:

FileHandle { fd: 3 }

See: https://developer.mozilla.org/en-US/docs/Web/API/File_Handle_API

Environment

System:
  OS: Windows 10 10.0.19043
  CPU: (4) x64 Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
Binaries:
  Node: 12.22.7 - C:\Users\...\AppData\Local\Temp\xfs-a9e56644\node.CMD
  Yarn: 3.1.0 - C:\Users\...\AppData\Local\Temp\xfs-a9e56644\yarn.CMD
  npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
@unzico unzico added the bug Something isn't working label Nov 23, 2021
@ericmutta
Copy link

Just ran into this too trying to generate a PDF with puppeteer. The stack trace for me is:

c:\[...]\YarnTest\.pnp.cjs:5162
  if (windowsPathMatch = p.match(WINDOWS_PATH_REGEXP)) p = `/${windowsPathMatch[1]}`;else if (uncWindowsPathMatch = p.match(UNC_WINDOWS_PATH_REGEXP)) p = `/unc/
${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
                           ^

TypeError: p.match is not a function
    at Object.toPortablePath (c:\[...]\YarnTest\.pnp.cjs:5162:28)
    at PosixFS.mapToBase (c:\[...]\YarnTest\.pnp.cjs:9952:18)
    at PosixFS.fsMapToBase (c:\[...]\YarnTest\.pnp.cjs:6659:19)
    at PosixFS.writeFilePromise (c:\[...]\YarnTest\.pnp.cjs:6536:46)
    at URLFS.writeFilePromise (c:\[...]\YarnTest\.pnp.cjs:6536:24)
    at Object.getReadableAsBuffer (c:\[...]\YarnTest\.yarn\unplugged\puppeteer-npm-12.0.0-0f876e526f\node_modules\puppeteer\lib\cjs\puppeteer\common\helper.js:250:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Page.pdf (c:\[...]\YarnTest\.yarn\unplugged\puppeteer-npm-12.0.0-0f876e526f\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:2104:16)
    at async c:\[...]\YarnTest\example-2.js:12:3

Using node v16.13.0 and yarn 3.1.1 on Windows 8.1.

@yarnbot

This comment has been minimized.

@yarnbot yarnbot added the stale Issues that didn't get attention label Dec 29, 2021
@merceyz merceyz added upholded Real issues without formal reproduction and removed stale Issues that didn't get attention labels Dec 29, 2021
@merceyz merceyz self-assigned this Jan 22, 2022
@alienzhangyw
Copy link

I got similar error when starting up unpacked electron app with yarn berry, but I fixed it.
According to yarn's doc about pnp, you can try add "NODE_OPTIONS" to your scripts.

"scripts": {
    "start": "node -r ./.pnp.cjs build/index.js",
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upholded Real issues without formal reproduction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants