Skip to content

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

Open
@marc0777

Description

@marc0777

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions