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

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

Open
marc0777 opened this issue Sep 20, 2024 · 0 comments
Open

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

marc0777 opened this issue Sep 20, 2024 · 0 comments
Labels
issue: bug Issue reporting a bug

Comments

@marc0777
Copy link

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/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/utils/load-config-file.js:18:13)
at Module.loadConfigFile (~/cms/node_modules/.pnpm/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/utils/load-config-file.js:37:14)
at loadPlugins (~/cms/node_modules/.pnpm/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@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/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/loaders/index.js:12:3)
at async Object.register (~/cms/node_modules/.pnpm/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/providers/registries.js:26:5)
at async Strapi.register (~/cms/node_modules/.pnpm/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/Strapi.js:322:7)
at async Strapi.load (~/cms/node_modules/.pnpm/@strapi+core@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+language_s62dddslq2bxwrlfinmqz5vbcm/node_modules/@strapi/core/dist/Strapi.js:314:5)
at async Module.develop (~/cms/node_modules/.pnpm/@strapi+strapi@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@codemirror+langua_zxfweiqacyjrhnmmqug74nt5xi/node_modules/@strapi/strapi/dist/node/develop.js:177:28)
at async action (~/cms/node_modules/.pnpm/@strapi+strapi@5.0.0_@babel+runtime@7.25.4_@codemirror+autocomplete@6.18.0_@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.

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
Projects
None yet
Development

No branches or pull requests

1 participant