remix-run/blues-stack

Can't import non-libraries from server.ts

Closed this issue · 2 comments

Have you experienced this bug with the latest version of the template?

yes

Steps to Reproduce

  1. run npx create-remix --template remix-run/blues-stack
  2. create app/foo.ts in base directory with contents export const bar = 'baz'
  3. add import { bar } from './foo' to server.ts
  4. run npm run setup && npm run build && npm run start

Expected Behavior

✅ app ready: http://localhost:3000

Actual Behavior

Error: Cannot find module '~/foo'

this is primarily due to how your app and server are built. at build time, they both are output at ./build, so trying to import from ./app/foo won't exist. but if you update that import to import { bar } from './index' it won't exist there either as it would have been treeshaken out by esbuild due to not being used during that build 😅.

as for "Error: Cannot find module '~/foo'" you can't use tsconfig path aliases without running it with node --require tsconfig-paths/register as node by default doesn't understand the alias.

See #84 (cc @mcansh )