Can't import non-libraries from server.ts
Closed this issue · 2 comments
ethangclark commented
Have you experienced this bug with the latest version of the template?
yes
Steps to Reproduce
- run
npx create-remix --template remix-run/blues-stack
- create
app/foo.ts
in base directory with contentsexport const bar = 'baz'
- add
import { bar } from './foo'
toserver.ts
- 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
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