airbrake / airbrake-js

Airbrake JavaScript Notifier
https://airbrake.io
MIT License
422 stars 139 forks source link

Relative import breaks Yarn Berry Plug'n'Play #1104

Closed rdadoune closed 3 years ago

rdadoune commented 3 years ago

🐞 bug report

Affected Package

The issue is caused by package @airbrake/node ### Is this a regression?

Yes. Looks like this bug was introduced ~6 months ago here: https://github.com/airbrake/airbrake-js/commit/78387b647b7fa2cd89b738171a1999ac29c989eb#diff-ee255d4819b7e98c3487cb7f6feb2964841189ce14b06654ea25507701df053b

Description

This relative import breaks Yarn 2 Plug'n'Play. Plug'n'Play doesn't use a traditional directory structure and instead uses a virtual file system so a reference to ../../browser is outside the scope of @airbrake/node and throws an error because it doesn't exist (each package is not in the same node_modules folder).

Screen Shot 2021-08-17 at 11 21 11 AM

https://github.com/airbrake/airbrake-js/blob/753c59c950a5d8e3ecc47dda8c40244419778269/packages/node/src/notifier.ts#L1-L2

πŸ”¬ Minimal Reproduction

https://gist.github.com/...

πŸ”₯ Exception or Error


Error: Qualified path resolution failed - none of those files can be found on the disk.

Source path: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.js
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.json
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.node
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.mjs
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.jsx
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.es6
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.es
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.cjs
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.ts
Not found: /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/browser.tsx

Require stack:
- /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/node/dist/notifier.js
- /dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/node/dist/index.js
- /dev/packages/app/src/lib/airbrake.ts
- /dev/packages/app/src/index.tsx
- /dev/packages/app/index.js
    at Function.external_module_.Module._resolveFilename (/dev/.pnp.cjs:60665:55)
    at Function.external_module_.Module._load (/dev/.pnp.cjs:60464:48)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object. (/dev/.yarn/cache/@airbrake-node-npm-2.1.5-bcc670293b-604e121d16.zip/node_modules/@airbrake/node/src/notifier.ts:2:1)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Module._compile (/dev/.yarn/cache/pirates-npm-4.0.1-377058e8fc-091e232aac.zip/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Object.newLoader [as .js] (/dev/.yarn/cache/pirates-npm-4.0.1-377058e8fc-091e232aac.zip/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:815:32)

🌍 Your Environment

@airbrake/* version:

"@airbrake/node": "^2.1.5"

Anything else relevant?

This issue specifically affects installations with Yarn 2 Berry pnp.

kyrylo commented 3 years ago

Thanks for the bug report. I can't remember why I used a relative import but there are more in the PR that you linked. Do you think all of them would have the same problem?

rdadoune commented 3 years ago

Yeah, but only for relative imports that reach outside the scope of the package.