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_REQUIRE_ESM on build when using Yarn v1. Incorrect dep resolution. #4109

Closed
denolfe opened this issue Nov 12, 2023 · 3 comments · Fixed by #4746
Closed

ERR_REQUIRE_ESM on build when using Yarn v1. Incorrect dep resolution. #4109

denolfe opened this issue Nov 12, 2023 · 3 comments · Fixed by #4746
Assignees
Labels
cloud-platform status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@denolfe
Copy link
Member

denolfe commented Nov 12, 2023

Link to reproduction

npx create-payload-app

Describe the Bug

A blank template is unable to deploy on cloud. It appears to be caused by a dependency deep in the chain being ESM-only.

CleanShot 2023-11-11 at 20 57 41
[2023-11-12 01:33:05] │ Running custom build command: yarn build
[2023-11-12 01:33:06] │ yarn run v1.22.19
[2023-11-12 01:33:06] │ $ yarn copyfiles && yarn build:payload && yarn build:server
[2023-11-12 01:33:06] │ $ copyfiles -u 1 "src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}" dist/
[2023-11-12 01:33:07] │ /workspace/node_modules/cliui/build/index.cjs:291
[2023-11-12 01:33:07] │ const stringWidth = require('string-width');
[2023-11-12 01:33:07] │                     ^
[2023-11-12 01:33:07] │ 
[2023-11-12 01:33:07] │ Error [ERR_REQUIRE_ESM]: require() of ES Module /workspace/node_modules/string-width/index.js from /workspace/node_modules/cliui/build/index.cjs not supported.
[2023-11-12 01:33:07] │ Instead change the require of index.js in /workspace/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
[2023-11-12 01:33:07] │     at Object.<anonymous> (/workspace/node_modules/cliui/build/index.cjs:291:21)
[2023-11-12 01:33:07] │     at Object.<anonymous> (/workspace/node_modules/yargs/build/index.cjs:2861:12)
[2023-11-12 01:33:07] │     at Object.<anonymous> (/workspace/node_modules/yargs/index.cjs:5:30)
[2023-11-12 01:33:07] │     at Object.<anonymous> (/workspace/node_modules/copyfiles/copyfiles:4:12) {
[2023-11-12 01:33:07] │   code: 'ERR_REQUIRE_ESM'
[2023-11-12 01:33:07] │ }
[2023-11-12 01:33:07] │ error Command failed with exit code 1.
[2023-11-12 01:33:07] │ info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[2023-11-12 01:33:07] │ error Command failed with exit code 1.
[2023-11-12 01:33:07] │ info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[2023-11-12 01:33:07] │ building: exit status 1
[2023-11-12 01:33:07] │ ERROR: failed to build

Other dependencies appear to be having the same issue:

Possible Solutions

  1. Cloud deployments for the template were working previously, determine what dep was updated to cause this - revert it.

  2. Our direct dependency is resend. See if updating that dependency fixes the reference

  3. Add a resolutions to the package.json. Not the best solution.

To Reproduce

  • npx create-payload-app -t blank
  • Deploy on cloud

Payload Version

2.1.1

Adapters and Plugins

No response

@denolfe denolfe added status: needs-triage Possible bug which hasn't been reproduced yet cloud-platform labels Nov 12, 2023
@denolfe denolfe changed the title Blank template unable to build on Cloud Blank template unable to build on Cloud due to downstream dependency Nov 12, 2023
@denolfe denolfe self-assigned this Nov 12, 2023
@denolfe
Copy link
Member Author

denolfe commented Nov 12, 2023

Looks like this is a yarn v1 package alias resolution issue: yarnpkg/yarn#4812

Closed as won't fix for Yarn v1 😒

@denolfe
Copy link
Member Author

denolfe commented Nov 12, 2023

Only workaround for yarn is to use this in the application's package.json:

"resolutions": {
  "jackspeak": "2.1.1"
}

@denolfe
Copy link
Member Author

denolfe commented Nov 13, 2023

Another avenue would be to update our templates to use yarn v2 and then specify as such in their package.json.

  "engines": {
    "yarn": "2.x"
  }

https://devcenter.heroku.com/articles/nodejs-support#specifying-a-yarn-version

@denolfe denolfe changed the title Blank template unable to build on Cloud due to downstream dependency Blank template unable to build with Yarn on Cloud due to downstream dependency Nov 13, 2023
@denolfe denolfe changed the title Blank template unable to build with Yarn on Cloud due to downstream dependency ERR_REQUIRE_ESM on build when using Yarn v1 Blank template. Incorrect dep resolution. Nov 20, 2023
@denolfe denolfe changed the title ERR_REQUIRE_ESM on build when using Yarn v1 Blank template. Incorrect dep resolution. ERR_REQUIRE_ESM on build when using Yarn v1. Incorrect dep resolution. Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloud-platform status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
1 participant