next-transpile-modules: "yarn workspace" commands don't work
Hello.
- I HAVE READ THE FAQ AND MY PROBLEM WAS NOT DESCRIBED THERE
Are you trying to transpile a local package or an npm package? Local package
Describe the bug
../components/src/Header.tsx 3:5
Module parse failed: Unexpected token (3:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import React from 'react'
|
> type Props = React.PropsWithChildren<{
| className?: string
| }>
To Reproduce
$ git clone https://github.com/aswbot/ntm-transpile-error.git && cd ntm-transpile-error
$ yarn
$ yarn workspace @app/web dev
Expected behavior It should work out of the box afaik, no babel configuration as Next comes with TypeScript support. It is weird but removing the types does work. It only complains about type annotations/declarations. š¤ Any ideas?
Setup
- Next.js version: 9.5.1
next-transpile-modulesversion: 4.0.2- Node.js version: 14.3.0
npm/yarnversion: Yarn 1.22.4- Operating System: Windows 10 x64
- Webpack 4 or 5: Both 4 and 5
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 13
- Comments: 63 (24 by maintainers)
Commits related to this issue
- SBERDOMA-121 add required main for next-transpile-modules https://github.com/martpie/next-transpile-modules/issues/101#issuecomment-741974772 — committed to open-condo-software/condo by pahaz 3 years ago
- SBERDOMA-121 add required main for next-transpile-modules https://github.com/martpie/next-transpile-modules/issues/101#issuecomment-741974772 — committed to open-condo-software/condo by pahaz 3 years ago
- SBERDOMA-121 add required main for next-transpile-modules https://github.com/martpie/next-transpile-modules/issues/101#issuecomment-741974772 — committed to open-condo-software/condo by pahaz 3 years ago
- SBERDOMA-121 add required main for next-transpile-modules https://github.com/martpie/next-transpile-modules/issues/101#issuecomment-741974772 — committed to open-condo-software/condo by pahaz 3 years ago
Recently Iām trying to upgrade next.js to v10.x from v9.3.6 but getting error in the
buildmode.devmode works in both next.js v10.x and v9.x.this is the sample repo: https://github.com/lava-x/test-rnw-monorepo
dev is working:
build is not working
NPM packages version
"next": "10.0.6""next-transpile-modules": "6.3.0"Environment yarn
1.22.10nodev15.11.0macOS Big Sur11.2.2arm-based macbookM1this is the next.config.js
there is another person facing the same issue as well: https://github.com/brunolemos/react-native-web-monorepo/issues/69
@samuelcastro please read the breaking changes in v5/6 and how to get through them, I bet you donāt have a
mainfield in@elements/uiāspackage.json@martpie thanks for the reply.
I was able to resolve the error by modifying the path of the shared package in
next.config.js:from:
const withTM = require('next-transpile-modules')(['shared']);to:const withTM = require('next-transpile-modules')(['../shared']);I donāt think this is an actual solve as none of the examples require this. Itās also lead to new
module not founderrors in the shared app when deploying to Vercel (anything that the shared app imports e.g.@chakra-ui/reactthrows an error on deployment, but works locally). Fun times šcf. https://github.com/martpie/next-transpile-modules/issues/101#issuecomment-776941232 The problem is explained here, I just donāt know how to solve it.
@martpie As suggested by you, I removed all these plugins, deleted my node_modules package and started adding these plugins one by one, and this time, I donāt know how everything worked out. Now I am able to run the app from root folder as well as from the nextjs folder. Donāt know where I messed up, but now everything is working fine.
Thank you so much for all your support.
I made the mistake of not updating the usage when updating from a much older version (2.3). Worth checking in case this is anyone elseās issue.
I have no clue why this made the difference for me, but using your comment @aswbot I was able to get mine working too. I havenāt been able to pinpoint what changed between these repos, but simply changing my
baseUrl: '.'tobaseUrl: 'packages'(like you had actually removed) solved it for me.@martpie Thanks for the test and issue hunting I actually found the reason why it was not transpiling correctly.
Firstly I tried what you proposed but still had no luck. I then thought it had something to do with scoped packages so I tried making the components just
app-componentsinstead of@app/componentsand it did actually work so that was first thing (no idea why tho, shouldnāt be the case š¤·āāļø)The real reason was my tsconfig.json which had
I removed baseUrl and paths for ready to be transpiled local packages and it started working. Not sure if that is the case for @dmeents but could be the issue and it is then easy to solve.
I think it would sound perfectly reasonable to pass a directory as an option to
next-transpile-modulesto fix this. Next.js already advises you to pass it for setting up the Jest preset: https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compilerThis is what it could look like as an option:
@martpie that did it! Thank you so much!
For anyone running into this issue when deploying to Vercel, make sure you update your build & deploy settings to use yarn and not npm š¤¦āāļø
@belgattitude Thanks. Creating a
index.tsand exporting all components from there did the job for me!@darwin403 I havenāt had problem with scoped packages and yarn or even yarn-3.0.0-rc.2 (not yet pnp).
I think you should be able to upgrade to latest NTM by
See the latest NTM doc about it.
PS:
ā ļø For anyone interested in diving into the issue ā ļø
the problem is most probably coming from this line:
https://github.com/martpie/next-transpile-modules/blob/2d935beb70f8420ca42dd0d7bb2ca6755ff8d38c/src/next-transpile-modules.js#L21
I imagine in a
yarn workspacecommand,process.cwd()resolves to the root of the workspaces, but we want it to be resolved to the root of the Next.js application.If anyone knows a quick way to fix this, feel free to post here a hint or submit a PR.
resolveSymlinks, in 99.9% of the cases, you donāt need itnext-transpile-modules), so this is entirely possible there is a conflict between the three pluginsnext.config.jsand see if it changes something (cf README)If you manage to identify which combination causes the issue, Iāll be able to dive in and see what causes the issue, but this is a different issue than this one (which is about
yarn workspace), so Iād recommend creating a new issue.To anyone facing this issue
-> please in the meantime, donāt use
yarn workspace blabla dev, run theyarn devcommand from your Next.js application directory directly.I know why this is happening, I will see how it can be solved (Iām not really sure how)
I will try to investigate this issue this week guys. I may have time to land a hotfix before #132 lands
Our team was running into this issue recently as well.
If your
next-transpile-modulesconfig used to look something like@alias/core, changing it to bepath/to/actual/coreseems to fix it. In our case, we had a set up that looked like:This would point to a folder in our repo that had a
package.jsonfile with the package name@alias/core, and in our tsconfig we had a paths setting that established the alias for typescript. To finally get this working with the package versions outlined in this issue, we changed our withTM setup to look like:After doing so and running our dev environment, things seemed to start working as expected again. Not sure what changed.
In our repo we use yarn workspaces, we have a number of folders with package.json files and whatnot, though, we donāt have everything stored in the same folder, maybe thatās part of this issue? š¤·
@aswbot Can you try using
@appinnext.config.jsinstead of@app/componentsand tell me if it works? I think the problem comes from the scoped package name + what you defined innext.config.js. I added integration tests for React components and they work well.Weird, we have a test for this case: https://github.com/martpie/next-transpile-modules/blob/master/src/__tests__/__apps__/yarn-workspaces/app/pages/test-local-typescript-module.tsx
Maybe I should try to add a react component as well
Edit: see https://github.com/martpie/next-transpile-modules/issues/101#issuecomment-778690321