remix-run / blues-stack

The Remix Stack for deploying to Fly with PostgreSQL, authentication, testing, linting, formatting, etc.
https://remix.run/stacks
MIT License
961 stars 236 forks source link

Can't import non-libraries from server.ts #78

Closed ethangclark closed 2 years ago

ethangclark commented 2 years ago

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'

mcansh commented 2 years ago

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.

ethangclark commented 2 years ago

See https://github.com/remix-run/blues-stack/pull/84 (cc @mcansh )