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

strapi-5@0.1.0 error: Cannot find module '@strapi/email/package.json' on first start #20298

Open
rbjs opened this issue May 11, 2024 · 11 comments
Assignees
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members version: 5

Comments

@rbjs
Copy link

rbjs commented May 11, 2024

Bug report

Required System information

  • Node.js version: v20.12.2
  • NPM version: 10.5.2
  • Strapi version: 5.0.0-beta.7
  • Database: n/a
  • Operating system: macOS 13.6.4
  • Is your project Javascript or Typescript: n/a

Describe the bug

'npm run develop' returns fatal error on first run after fresh installation.

strapi-5@0.1.0 develop
strapi develop

⠋ Loading Strapi⠋ Building build context
[INFO] Including the following ENV variables as part of the JS bundle:
- ADMIN_PATH
- STRAPI_ADMIN_BACKEND_URL
- STRAPI_TELEMETRY_DISABLED
✔ Building build context (47ms)
✔ Creating admin (378ms)
[ERROR] There seems to be an unexpected error, try again with --debug for more information
`
│ Error: Cannot find module '@strapi/email/package.json'
│ Require stack:
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/loaders/plugins/get-enabled-plugins.js
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/loaders/plugins/index.js
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/loaders/index.js
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/providers/registries.js
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/providers/index.js
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/Strapi.js
│ - /Users/dev/strapi5/node_modules/@strapi/core/dist/index.js
│ - /Users/dev/strapi5/node_modules/@strapi/strapi/dist/cli/commands/admin/create-user.js
│ - /Users/dev/strapi5/node_modules/@strapi/strapi/dist/cli/commands/index.js
│ - /Users/dev/strapi5/node_modules/@strapi/strapi/dist/cli/index.js
│ - /Users/dev/strapi5/node_modules/@strapi/strapi/bin/strapi.js
│ at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
│ at Module._load (node:internal/modules/cjs/loader:984:27)
│ at Module.require (node:internal/modules/cjs/loader:1231:19)
│ at require (node:internal/modules/helpers:179:18)
│ at Module.getEnabledPlugins (/Users/dev/strapi5/node_modules/@strapi/core/dist/loaders/plugins/get-enabled-plugins.js:55:25)
│ at loadPlugins (/Users/dev/strapi5/node_modules/@strapi/core/dist/loaders/plugins/index.js:76:50)
│ at Module.loadApplicationContext (/Users/dev/strapi5/node_modules/@strapi/core/dist/loaders/index.js:16:5)
│ at Object.register (/Users/dev/strapi5/node_modules/@strapi/core/dist/providers/registries.js:26:17)
│ at Strapi.register (/Users/dev/strapi5/node_modules/@strapi/core/dist/Strapi.js:301:32)
│ at Strapi.load (/Users/dev/strapi5/node_modules/@strapi/core/dist/Strapi.js:293:16)

`

Steps to reproduce the behavior

npx create-strapi-app@beta my-project --quickstart
cd my-project
npm run develop

@rbjs rbjs changed the title error: Cannot find module '@strapi/email/package.json' on first start strapi-5@0.1.0 error: Cannot find module '@strapi/email/package.json' on first start May 11, 2024
@corvallo

This comment has been minimized.

@joshuaellis
Copy link
Member

@rbjs can you run npm ls @strapi/email and share the output please?

@joshuaellis joshuaellis added issue: bug Issue reporting a bug status: can not reproduce Not enough information to reproduce source: core:strapi Source is core/strapi package version: 5 severity: high If it breaks the basic use of the product labels May 14, 2024
Copy link
Contributor

This is a templated message

Hello @rbjs,

Thank you for reporting this bug, however we are unable to reproduce the issue you described given the information we have on hand. Can you please create a fresh project that you are able to reproduce the issue in, provide clear steps to reproduce this issue, and either upload this fresh project to a new GitHub repo or compress it into a .zip and upload it on this issue?

We would greatly appreciate your assistance with this, by working in a fresh project it will cut out any possible variables that might be unrelated.
Please note that issues labeled with status: can not reproduce will be closed in 14 days if there is no activity.

Thank you!

@LuisRodriguezLD
Copy link
Contributor

Usually I don't write comments like 'same here' but I'm also seeing this and I can provide more input.

Same env as OP but:

  • Using TS
  • Using SQLite

Running npm ls @strapi/email yields

project@0.1.0 /Users/user/dev/project
└─┬ @strapi/strapi@5.0.0-beta.7
  └── @strapi/email@5.0.0-beta.7

The file requiring this package is here -> https://github.com/strapi/strapi/blob/v5.0.0-beta.7/packages/core/core/src/loaders/plugins/get-enabled-plugins.ts

Let me know if you have additional questions

@joshuaellis
Copy link
Member

joshuaellis commented May 14, 2024

Thanks @LuisRodriguezLD, what package manager are you using? 😊

EDIT: and node version?

@LuisRodriguezLD
Copy link
Contributor

NPM 10.5.0
NODE 20.12.1

@joshuaellis joshuaellis added status: confirmed Confirmed by a Strapi Team member or multiple community members and removed status: can not reproduce Not enough information to reproduce labels May 15, 2024
@joshuaellis
Copy link
Member

The issue comes from the fact that only @strapi/strapi has @strapi/email listed as a dependency, but @strapi/core tries to load it dynamically without having it listed as a dependency, this will most likely break pnpm anyway.

@alexandrebodin || @innerdvations I think it's worth reviewing how plugins are loaded by strapi/core because whilst the immediate fix would be to add @strapi/email to the list of deps in @strapi/core I think it's a brittle solution considering that the package wants to load deps it doesn't know about and thus relies on package manager implementation which as we can see is subject to break. Made a loom to demonstrate the issue https://www.loom.com/share/a75b25cbed004b829d3df761bcef7a1e?sid=219dcfa1-79ec-4a2b-aa9f-5807c4fe4871

@joshuaellis joshuaellis added severity: critical If the issue has a security impact or breaks core usage of the product and removed severity: high If it breaks the basic use of the product labels May 15, 2024
@lerry

This comment was marked as spam.

@lunatiqqc

This comment was marked as spam.

@Convly
Copy link
Member

Convly commented May 23, 2024

I managed to reproduce it locally.

From what I've found, it comes down to hoisting settings:

  • if hoisting is enabled, no issue arise
  • if you add hoist=false to your project .npmrc (or disable hoisting globally), then dependency errors arise.

Note: This is something that also happen on v4 since its launch.

This is still a valid issue as package managers are slowly going toward "no hoisting by default" and we're definitely going to work on it, but we've decided to lower the priority as it's not a regression and has a straightforward workaround.

@Convly Convly added severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve and removed severity: critical If the issue has a security impact or breaks core usage of the product labels May 23, 2024
@LuisRodriguezLD
Copy link
Contributor

Thanks for looking into this @Convly
However, wouldn't it make sense to add this .npmrc file as part of the initial template?
I feel this could make life easier for devs who just want to try Strapi without needing to dig into why it's randomly failing

I'm happy to work on this if you think is a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members version: 5
Projects
Status: In progress
Status: To triage
Status: To review
Development

No branches or pull requests

8 participants