Error while building new plugin, cannot find dist/server


I have created a new strapi typescript project, just added a few content types so it’s not customised.

Then i created a plugin:
npm run strapi generate plugin

Added the pugins.ts file as recommended, and tried to run strapi with the new plugin using
npm run build
npm run develop -- --watch-admin

This throws the following error:

> strapi-app@0.1.0 develop
> strapi develop --watch-admin

Error: Could not load js config file \strapi-app\src\plugins\test-plugin\strapi-server.js: Cannot find module './dist/server'
Require stack:
- \strapi-app\src\plugins\test-plugin\strapi-server.js

strapi-server.js looks like this:
'use strict';
module.exports = require('./dist/server');

How do i fix this?

System Information
  • Strapi Version: 4.13.7
  • Operating System: win10
  • Database: mysql
  • Node Version: 20.7.0
  • NPM Version: 10.1.0
  • Yarn Version: -

I run today into the same problem - you need to build your plugin first.

Add the following in your main package.json

 "scripts": {
    "prebuild": "cd src/plugins/<plugin name> && npm run build",
1 Like

Yes, that’s correct.
I got some errors while trying manual build, that led me to the conclusion that strapi’s build should do this.

The source of the problem was that react types were of version 17, while react was at 18 in package.json (typescript project on npm).

I too have noticed this. Is that what causes the error when trying to run with yarn develop after the steps you mentioned above? (Fresh plugin generated with Typescript, install node_modules for plugins, build and then run.

ERROR in ./src/plugins/test/admin/src/pages/App/index.tsx:17:8
TS2786: 'Switch' cannot be used as a JSX component.
  Its type 'typeof Switch' is not a valid JSX element type.
    Type 'typeof Switch' is not assignable to type 'new (props: any, deprecatedLegacyContext?: any) => Component<any, any, any>'.
      Construct signature return types 'Switch' and 'Component<any, any, any>' are incompatible.
        The types returned by 'render()' are incompatible between these types.
          Type 'React.ReactNode' is not assignable to type 'import("/home/harvey/Projects/strapi-ts/node_modules/@types/react/index").ReactNode'.
            Type '{}' is not assignable to type 'ReactNode'.
    15 |   return (
    16 |     <div>
  > 17 |       <Switch>
       |        ^^^^^^
    18 |         <Route path={`/plugins/${pluginId}`} component={HomePage} exact />
    19 |         <Route component={AnErrorOccurred} />
    20 |       </Switch>

Yes, think this an issue on react side. Had to install react types v18 manually.

1 Like