Railway deploy can't find dist

Hello. I’ve moved an existing Strapi project over to Typescript (fresh build, not converting the existing JS project) and am having trouble getting it to build and deploy on Railway. It has a single custom plugin (also written in TS).
Error message is pasted below but seems that the plugin fails to build/find the dist folder created by typescript.

It works fine locally but just not when deployed (deployed fine as JS but was horrible to develop without good type support)…

yarn run v1.22.19
$ strapi start
[2023-03-28 10:21:17.589] debug: ⛔️ Server wasn't able to start properly.
[2023-03-28 10:21:17.591] error: Could not load js config file /app/src/plugins/property-import/strapi-server.js: Cannot find module './dist/server'
Require stack:
- /app/src/plugins/property-import/strapi-server.js
- /app/node_modules/@strapi/utils/lib/import-default.js
- /app/node_modules/@strapi/utils/lib/index.js
- /app/node_modules/@strapi/strapi/lib/services/entity-service/components.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/queries/entity.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/queries/index.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/providers/local-destination/strategies/restore/index.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/providers/local-destination/strategies/index.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/providers/local-destination/index.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/providers/index.js
- /app/node_modules/@strapi/data-transfer/lib/strapi/index.js
- /app/node_modules/@strapi/data-transfer/lib/index.js
- /app/node_modules/@strapi/strapi/lib/commands/transfer/utils.js
- /app/node_modules/@strapi/strapi/bin/strapi.js
Error: Could not load js config file /app/src/plugins/property-import/strapi-server.js: Cannot find module './dist/server'
Require stack:

Here is my plugins/property-import/strapi-server.js file:

'use strict';

module.exports = require('./dist/server');

Any ideas welcomed :pray:

System Information
  • Strapi Version: 4.8.2
  • Operating System:
  • Database: Postgres
  • Node Version:
  • NPM Version:
  • Yarn Version:

your problem is that dist folder is not built with the main strapi program, and it is expected to be already built.

Add the following in your main package.json

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

if you have any dependencies that you want to install from the plugin, or you can add dependencies in your main package.json

"workspaces": [
    "./src/plugins/<plugin name>",
  ],
1 Like

Thanks for this, I’m aiming Railway as my new host for my portfolio.

Thank you.

You also might be interested in this: