strapi / sdk-plugin

CLI toolkit for developing a Strapi plugin
Other
4 stars 4 forks source link

Tracking Issue: Strapi 5 plugin template currently out-of-date/incorrect #1

Closed n-alonso closed 3 months ago

n-alonso commented 4 months ago

Bug report

Required System information

Describe the bug

The plugin does not build correctly and throws some errors about module not found, so the actual Strapi instance cannot start.

Steps to reproduce the behavior

  1. Create a fresh v5 project
  2. Yarn strapi plugin:init to create a new plugin
  3. cd into the plugin
  4. Yarn install && yarn build (which runs yarn strapi plugin:build)
  5. cd back into the root
  6. Yarn build && yarn develop

Expected behavior

The plugin builds correctly and the Strapi instance is able to start

Code snippets | Errors

This is the output of building the plugin:

nick-aj@Nicolass-MacBook-Pro  ~/Playground/ob-plugin/src/plugins/ob-plugin   main ±  yarn build
yarn run v1.22.19
$ strapi plugin:build
✔ Verified package.json
✔ Created build context
Building type files:
   entries:
    – ob-plugin/admin/src/index.ts ./admin/src/index.ts -> ./dist/admin/src/index.d.ts
    – ob-plugin/server/src/index.ts ./server/src/index.ts -> ./dist/server/src/index.d.ts
[ERROR]  admin/src/index.ts:1:42 - TS2307: Cannot find module './utils/prefixPluginTranslations' or its corresponding type declarations.
[ERROR]  admin/src/pages/App.tsx:2:10 - TS2305: Module '"react-router-dom"' has no exported member 'Switch'.
[INFO]  Option '--incremental' can only be specified using tsconfig, emitting to single file or when option '--tsBuildInfoFile' is specified.
[INFO]  Option '--incremental' can only be specified using tsconfig, emitting to single file or when option '--tsBuildInfoFile' is specified.
Building javascript files:
  format: cjs
   target:
    - esnext
   entries:
    – ob-plugin/bundle_cjs_0: ./admin/src/index.ts → ./dist/admin/index.js
Building javascript files:
  format: es
   target:
    - esnext
   entries:
    – ob-plugin/bundle_esm_0: ./admin/src/index.ts → ./dist/admin/index.mjs
Building javascript files:
  format: cjs
   target:
    - node18.0
   entries:
    – ob-plugin/bundle_cjs_1: ./server/src/index.ts → ./dist/server/index.js
Building javascript files:
  format: es
   target:
    - node18.0
   entries:
    – ob-plugin/bundle_esm_1: ./server/src/index.ts → ./dist/server/index.mjs
[ERROR]  Failed to compile TypeScript definitions
error Command failed with exit code 1.

Which results in the following error on yarn develop:

[ERROR]  There seems to be an unexpected error, try again with --debug for more information 

││   Error: Could not load js config file /Users/nick-aj/Playground/ob-plugin/src/plugins/ob-plugin/strapi-server.js: Cannot find module './dist/server'  
││   Require stack:  
││   - /Users/nick-aj/Playground/ob-plugin/src/plugins/ob-plugin/strapi-server.js  
││   - /Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/utils/dist/index.js  
││   - /Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/strapi/dist/cli/commands/admin/create-user.js  
││   - /Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/strapi/dist/cli/commands/index.js  
││   - /Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/strapi/dist/cli/index.js  
││   - /Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/strapi/bin/strapi.js  
││       at loadJsFile (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/utils/load-config-file.js:18:13)  
││       at Module.loadConfigFile (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/utils/load-config-file.js:37:14)  
││       at loadPlugins (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/loaders/plugins/index.js:91:41)  
││       at async Promise.all (index 3)  
││       at async Module.loadApplicationContext (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/loaders/index.js:12:3)  
││       at async Object.register (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/providers/registries.js:25:5)  
││       at async Strapi.register (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/Strapi.js:301:7)  
││       at async Strapi.load (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/core/dist/Strapi.js:293:5)  
││       at async Module.develop (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/strapi/dist/node/develop.js:177:28)  
││       at async action (/Users/nick-aj/Playground/ob-plugin/node_modules/@strapi/strapi/dist/cli/commands/develop.js:18:5)    
innerdvations commented 3 months ago

All the type errors have now been resolved, so I'm closing this one.