[bug]: can't `require` some dependencies on server component

Aperta
#60 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
backend, tooling

Direzione di ricerca

Start with the generated server component and the example service.js from the reproduction, then inspect the output at dist/server/index.js after adding uuid with require. Reproduce the failure using the listed sdk-plugin init and Strapi develop steps. Done means the generated plugin starts successfully and the server service can import and use the dependency without a dynamic try wrapper.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

issue: bug severity: low
What version of @strapi/sdk-plugin are you using?
  • npm version: 10.8.2
  • node version: 20.17.0
  • @strapi/sdk-plugin version: 5.2.6
What's Wrong?

Using the template created by sdk-plugin for Strapi v5 some imports inside the server component don't work. Building the plugin itself seems to work without problem, however once I try to start Strapi 5.0.0 I get the following error:

Error: Could not load js config file ~/test-plugin/dist/server/index.js: Cannot destructure property 'v4' of 'require$$0__default.default' as it is undefined.
at loadJsFile (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/utils/load-config-file.js:18:13)
at Module.loadConfigFile (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/utils/load-config-file.js:37:14)
at loadPlugins (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/loaders/plugins/index.js:118:41)
at async Promise.all (index 3)
at async Module.loadApplicationContext (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/loaders/index.js:12:3)
at async Object.register (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/providers/registries.js:26:5)
at async Strapi.register (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/Strapi.js:322:7)
at async Strapi.load (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/Strapi.js:314:5)
at async Module.develop (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+langua_zxfweiqacyjrhnmmqug74nt5xi/node_modules/@strapi/strapi/dist/node/develop.js:177:28)
at async action (~/cms/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@codemirror+langua_zxfweiqacyjrhnmmqug74nt5xi/node_modules/@strapi/strapi/dist/cli/commands/develop.js:18:5)

This started happening only from RC.18 to the stable version, instead since the first RC up to RC.17 it was working without problems.

To Reproduce
  1. Create plugin with npx @strapi/sdk-plugin@latest init test-plugin, with TypeScript disabled.
  2. Import a dependency npm install uuid
  3. Use dependency on server. For example, I changed service.js like this:
'use strict';

const {v4} = require("uuid")

const service = ({ strapi }) => ({
  getWelcomeMessage() {
    return 'Welcome to Strapi 🚀, uuid: ' + v4();
  },
});

module.exports = service;
  1. Include plugin and start Strapi npm strapi develop
  2. Strapi crashes while trying to start, with the error above.

The issue can be circumvented by requiring uuid dynamically wrapping in a try, but that shouldn't be necessary.

Expected Behaviour

Strapi should start successfully, correctly importing the dependency.

Lingua principale
TypeScript
Stelle
24
Fork
13
Merge medio
5g 3h
PR unite (30g)
5

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di strapi/sdk-plugin

Tutte le issue di strapi/sdk-plugin

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.