Closed kettanaito closed 2 years ago
Interesting that I can import TS modules from packages/ui
without issues. This makes me thing I'm not setting up the TS correctly with a newly added repo server
. This is what I have in packages/server/tsconfig.json
:
{
"extends": "tsconfig/base.json",
"include": ["."],
"exclude": ["node_modules"]
}
Should I add something else here?
Does your new package contains a package.json
? If so, did you add a main
entrypoint or a files
array (https://docs.npmjs.com/cli/v8/configuring-npm/package-json#main)?
Also, make sure to add your new package
to both your app/web
package.json
and next.config.js
(see the require('next-transpile-modules')
array).
Hey! This is a Next.js / TypeScript problem and not directly related to turbo. See the documentation on https://www.npmjs.com/package/next-transpile-modules. You might also find it necessary to transpile your packages independently like in the design system example here https://github.com/vercel/turborepo/blob/main/examples/design-system/packages/acme-core/package.json
Thanks, @jaredpalmer.
@jaredpalmer I am not sure if this is related but having the error - Failed to load parser './parser.js' declared in '.eslintrc.json » eslint-config-next/core-web-vitals » /Users/simon.colman/Documents/GitHub/oroton-turbo-repo/node_modules/eslint-config-next/index.js': Cannot find module 'next/dist/compiled/babel/eslint-parser'
This is a linting error - the next node modules folder is not hoisting up to the root node modules directory
@jaredpalmer I am not sure if this is related but having the error - Failed to load parser './parser.js' declared in '.eslintrc.json » eslint-config-next/core-web-vitals » /Users/simon.colman/Documents/GitHub/oroton-turbo-repo/node_modules/eslint-config-next/index.js': Cannot find module 'next/dist/compiled/babel/eslint-parser'
This is a linting error - the next node modules folder is not hoisting up to the root node modules directory
This happens when your nextjs and eslint-config-next dependencies are not in sync i.e. you updated next but forgot to update eslint-config-next.
@jaredpalmer:
You might also find it necessary to transpile your packages independently like in the design system example here https://github.com/vercel/turborepo/blob/main/examples/design-system/packages/acme-core/package.json
This solution has the drawback that you have to build a package after every change to the package before any other package will recognize the change. That's not the case with Next.js-transpiled packages.
If I have to live with this drawback, I would restructure my repo to have fewer packages. I'm presently being prolific with packages to flatten the source tree and make code easier to locate.
This solution has the drawback that you have to build a package after every change to the package before any other package will recognize the change. That's not the case with Next.js-transpiled packages.
I solved this problem by using the following package.json
configuration:
"types": "src/index.ts"
instead of this, which appears in many of the example repos:
"types": "dist/index.d.ts"
I do wonder if I have to use the latter in publishable repos, though.
Faced a similar problem , and solved it by adding transpilePackages: ["@repos/ui"]
to next.config.js
at workspace level :)
What version of Turborepo are you using?
1.1.1
What package manager are you using / does the bug impact?
npm
What operating system are you using?
Mac
Describe the Bug
I have a package under
packages/server
written in TypeScript. I'm trying to import that package inapps/web
but getting the following error on runtime:This implies that NextJS can't import a TS module outside of its directory (those are not transpiled per https://github.com/vercel/next.js/issues/5666).
Expected Behavior
I expect that TS modules can be freely imported across the monorepo, since that's the main point of introducing one.
To Reproduce
npx create-turbo@latest
.mkdir packages/server
touch packages/server/index.ts
export const value: Foo = { username: 'john' }
yarn dev
(alias forturbo run dev --parallel
).http://localhost:3000/api/foo
.