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

diffArrays deep require breaks Prettier 2.6 in Node.js 17.5.0 #12275

Closed
gabrielmaldi opened this issue Feb 11, 2022 · 4 comments · Fixed by #12462
Closed

diffArrays deep require breaks Prettier 2.6 in Node.js 17.5.0 #12275

gabrielmaldi opened this issue Feb 11, 2022 · 4 comments · Fixed by #12462
Labels
scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program

Comments

@gabrielmaldi
Copy link

Environments:

  • Prettier Version: 2.6.0-dev
  • Running Prettier via: CLI
  • Runtime: Node.js v17.5.0, npm 8.4.1
  • Operating System: macOS 12.2

Steps to reproduce:

  1. Install Node.js v17.5.0 and npm 8.4.1
  2. Install Prettier 2.6.0-dev
  3. Run prettier: npx prettier --write .

Expected behavior:

Prettier works.

Actual behavior:

Prettier breaks:

node:internal/modules/cjs/loader:488
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/diff/array.js' is not defined by "exports" in /repo/node_modules/diff/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:429:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:705:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/repo/node_modules/prettier/src/main/core.js:4:24) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v17.5.0

I tracked the problem to this line:

const { diffArrays } = require("diff/lib/diff/array.js");

If I change it to:

const { diffArrays } = require("diff");

Prettier works.

Alternatively, If I change this line in https://github.com/kpdecker/jsdiff:

https://github.com/kpdecker/jsdiff/blob/d358a573dc38fb89dd5ee296805e29f75c932a58/package.json#L40

To:

"./*": "./*"

Prettier works too.

Thanks!

@fisker
Copy link
Member

fisker commented Feb 11, 2022

Thanks for the information, do you think we can ask diff to fix?

@gabrielmaldi
Copy link
Author

I thought about it, but the diff repo hasn't been active; the last commit is from 2020 and I don't see issues or PRs being answered. So I think that if we file a ticket there, it will probably take a long time for it to get released to npm (if it ever does). Perhaps there's something we can do in Prettier to fix this before 2.6 is released?

@fisker
Copy link
Member

fisker commented Feb 11, 2022

We can bundle it into vendors

"vendors:bundle": "node ./scripts/vendors/bundle-vendors.mjs",

@fisker
Copy link
Member

fisker commented Feb 14, 2022

I've sent a PR to the upstream, let's see if it will get merged. kpdecker/jsdiff#351

@fisker fisker added scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program labels Feb 14, 2022
@fisker fisker mentioned this issue Mar 15, 2022
4 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants