How to properly export module / publish package ("Cannot find module")

95 views Asked by At

I tried to do a basic plugin for Backstage (backstage.io by Spotify) following tutorial from their website (https://backstage.io/docs/plugins/create-a-plugin). It works when running inside the app created with @backstage/create-app.

I published the package to npm: https://www.npmjs.com/package/backstage-dev-friends-days but when I install it using yarn add in another Backstage instance app I'm getting Cannot find module 'backstage-dev-friends-days' or its corresponding type declarations in the line with import { DevFriendsDayCard } from 'backstage-dev-friends-days';

Before running yarn publish I run tsc, but I feel some lack of knowledge about TS and JS and might put something wrong in tsconfig.json or package.json.

The plugin code is here: https://github.com/piatkiewicz/backstage-plugins/tree/main/dev-friends-days

1

There are 1 answers

0
Piotrek On

ok, finally works, can't explain it in details, but those are working files:

tsconfig.json

{
  "extends": "@backstage/cli/config/tsconfig.json",
  "include": [
    "src",
    "dev"
  ],
  "exclude": ["node_modules"],
  "compilerOptions": {
    "outDir": "dist-types",
    "rootDir": "."
  }
}

package.json

//...
  "files": [
    "dist"
  ],
  "private": false,
  "publishConfig": {
    "access": "public",
    "main": "dist/index.esm.js",
    "types": "dist/index.d.ts"
  },
//...

Did just run "tsc" from the main catalog / with tsconfig and then publish.