Search code examples
typescriptsvelterollupyarn-workspaces

Svelte + Rollup can't find Typescript file in Yarn workspaces


How can I make rollup in the folder "frontend" include a file located in the folder "common"?

- root
| - package.json
| - frontend
  | - index.svelte
  | - rollup.config.js
  | - package.json
| - backend
  | - index.ts
  | - package.json
| - common
  | - status.ts 
  | - package.json

root/package.json

{
    "private": true,
    "workspaces": [
        "backend",
        "common",
        "frontend"
    ]
}

root/frontend/package.json

{
  "name": "my-project-frontend",
  ...
  "dependencies": {
     ...
     "my-project-common": "^0.1.3",
  }
}

root/common/package.json

{
    "name": "my-project-common",
    "version": "0.1.4"
}

root/common/status.ts

export const StatusLabel = {
    CREATED: 'CREATED',
    QUEUED: 'QUEUED',
    RUNNING: 'RUNNING',
    FINNISHED: 'FINNISHED'
}

root/frontend/index.svelte

 import { StatusLabel } from "my-project-common/status";

this returns the error message when building

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
my-project-common/status (imported by index.svelte)

Solution

  • The link in the error takes you to a page that says:

    Rollup will only resolve relative module IDs by default

    So I would make that import relative like:

    import { StatusLabel } from '../common/status'