i have a yarn
workspace
monorepo
where different packages contain reusable code. like
@pkg/styles
,
@pkg/ui-components
all of these packages are es modules
(import export statements)
and are used in my non ssr application built by webpack like this.
for example
import { box } from '@pkg/styles'
import {Button} from '@pkg/ui-components'
now i need to add remix-run
to the same monorepo and things work fine until i start importing these local packages. i get this error
import box from './box';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
if i am not wrong this is happening because esbuild
expects all node_modules
to be pre compiled. and simply ignores them in the transpile phase.
and i need to tell my transpiler to consider my local packages in the transpilation which is super easy to do when we are using webpack
. but i am not sure how to do it in remix-run
and esbuild that it uses internally. there are few issues on remix-run github but nothing seem to be helpful.