Replies: 118 comments 20 replies
-
|
Beta Was this translation helpful? Give feedback.
-
I hope you mean custom webpack config. That's doable. But this sits in a existing loader. Getting that is somewhat harder.
Awesome. I'll update.
|
Beta Was this translation helpful? Give feedback.
-
Hey, As I'm starting my own website I'm trying new techs like Lerna/Next/Styled... and would be happy to provide early feedback on this. I've opened a duplicate issue where I tried to import/transpile a CRA-based module in my NextJs module but didn't know how to make the transpilation happen (note that I'd like to keep my module runnable as a standalone) I've also noticed that Babel, also based on Lerna, is transpiling each modules before exposing them, but it looks to me better to do like @arunoda suggest and let the client app do the transpiling. I'd like to have a single babel config for my client and share that config with all my decoupled modules. That's probably not so easy if I want to keep ability to run my modules as standalone, outside of Next runner My current test project is here: https://github.com/slorber/playground/ I'll try to upgrade it as soon as there's a fork/PR. @arunoda are you working on it? |
Beta Was this translation helpful? Give feedback.
-
@slorber currently we are focusing on 2.0 release and we are fine tuning stuff and finding bugs as possible as we can. I haven't started work on this but we can do this just after 2.0. |
Beta Was this translation helpful? Give feedback.
-
Ok so I'll make a fork. I'm already running against 2.0.0 beta because I'm not building a critical website and I don't think webpack 1.13 resolve jsnext:main/module field. I'm not a bundler expert but I think I'd rather use "module" field of package.json no? "main" seems for already transpiled code as far as I know. But as the webpack config allows to include/exclude transpilation I'm not sure it's relevant. Any recommendation on which of the 3 fields I'd rather use? |
Beta Was this translation helpful? Give feedback.
-
@slorber I think webpack only supports |
Beta Was this translation helpful? Give feedback.
-
Hmm according to what I've seen in practice against Next 2.x I've seen module works (but fails later at runtime because not transpiled) while jsnext:main did not work (as far as I remember). But it's supposed to be supported. Anyway, jsnext:main or module does not seem to be the solution to this problem so for company-internal modules just enabling transpilation is probably enough |
Beta Was this translation helpful? Give feedback.
-
The community has not agreed on one approach right? For example, I was able to use Ref: https://github.com/rauchg/blog/blob/master/components/post/youtube.js |
Beta Was this translation helpful? Give feedback.
-
Yes that makes sense to always transpile before publish because you don't know who/how the module will be consumed and you don't want to force the client to setup appropriate babel settings for your lib. That's what Rollup suggest: to publish the module transpiled in different ways so that bundler can decide which to use. But for company internal packages, the transpilation settings might be the same across several project (like a babel preset) and it makes sense to me to let the client bundler to transpile all the company dependencies |
Beta Was this translation helpful? Give feedback.
-
Very much agree @slorber - this would be very handy for internal modules if you're breaking your project up and isolating things as much as possible. And @rauchg / @arunoda supporting RegExp's would be really nice, so you could have one entry that catches all the company internal modules, using say the NPM org namespace:
|
Beta Was this translation helpful? Give feedback.
-
Beautiful suggestion @philcockfield |
Beta Was this translation helpful? Give feedback.
-
Hey maybe it could be worth offering some presets. It looks to me most tools (Lerna/npm link...) rely on symlinks so why not something as simple as: module.exports = {
transpileModules: ["symlinks"]
} |
Beta Was this translation helpful? Give feedback.
-
The more I use 🚀🤖 |
Beta Was this translation helpful? Give feedback.
-
I'm working on this today :) |
Beta Was this translation helpful? Give feedback.
-
@philcockfield give this a try: #749 |
Beta Was this translation helpful? Give feedback.
-
Also I am willing to pay if that can help as |
Beta Was this translation helpful? Give feedback.
-
i agree with that, next-transpile-modules just broke with next 10.0.8 and I think its time to rethink that |
Beta Was this translation helpful? Give feedback.
-
Any specific problem ? Asking cause I'm using it lot and upgrade regularly (even on 10.0.8, see https://github.com/belgattitude/nextjs-monorepo-example... but in private repos too).
node_modules seems a big hack 😄 , I feel like latest version of next-transpile-modules are pretty well done... That said a built-in would be welcome.
|
Beta Was this translation helpful? Give feedback.
-
First line of the code of next-transpile-modules /**
* disclaimer:
*
* THIS PLUGIN IS A F*CKING BIG HACK.
*
* don't even try to reason about the quality of the following lines of code.
*/ |
Beta Was this translation helpful? Give feedback.
-
👋 😅 I cannot speak in the name of Vercel, but I have talked a little bit with Tim a while ago. They are aware of this problem and they understand there is a real need for this. I offered my help to work on an official solution. It's getting higher and higher in the backlog, but it's just not there yet. It will come (in time...)! in the meantime, I'll keep maintaining We all just need to be patient. Sidenote: if your usecase is IE11 support, I cannot encourage you enough to convince your n+1 to drop support for it. There are plenty of good reasons for it, but the one they (managers) will listen to is probably money. So if you can convince them it costs you more money to support IE11 than it brings, you may be able to succeed in your "negotiations" :p |
Beta Was this translation helpful? Give feedback.
-
tbh, i don't remember, it throw some webpack error (unrecognized option), but i decided to remove next-transpile-modules, because i just used it for lodash-es and switched to normal lodash (and babel-plugin-lodash to help with tree shaking) we also dropped support for IE in most of our projects (🥰), so "modern" packages are less of a problem now than it was
totally agree on that, try it. They will say that companies still use ie11, but thats more than often a lie. Most companies that i know had at least one other, modern browser installed and ie11 only for compatibilty reasons. Its just that their users are uneducated and/or installations are poorly managed. Also supporting IE means keeping it alive. So you invest that the problem persists. |
Beta Was this translation helpful? Give feedback.
-
I have not seen any errors with next-transpile-modules and next@10.0.8, it works fine. And I think it is better solution than having babel plugin (because then you need to have babel config and this is another can of worms). But I agree that it would be nice to have native nextjs solution for this, that could handle es imports at very least, this is the main case for me to use next-transpile-modules, because more and more libraries are using untranspiled esm imports. |
Beta Was this translation helpful? Give feedback.
-
@rauchg any updates around this? This issue has been around for sometime, and packaging dependencies is actually a more complex situation now than in it was in 2017. It'd be great to know where this landed. |
Beta Was this translation helpful? Give feedback.
-
Hey Everyone, this package right here is a great, I would say stable solution for this issue while the guys at Vercel close this. https://www.npmjs.com/package/next-transpile-modules In my case, next was having issues transpiling this package: https://github.com/tbleckert/react-select-search 'next-transpile-modules' really solved it for me in a non corrosive, or invading way. Just transpiles the packages you specify (The ones you know are giving you a headache) |
Beta Was this translation helpful? Give feedback.
-
In Next 12 with create-next-app, this error happens when importing |
Beta Was this translation helpful? Give feedback.
-
This works for me – I revised this solution to non-mutate, posting for others const path = require('path');
module.exports = () => ({
webpack: (config, { defaultLoaders: { babel } }) => ({
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
include: [path.resolve(__dirname, '../')],
test: /\.(js|jsx|ts|tsx)$/,
use: [babel],
},
],
},
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
root: path.resolve(__dirname, '../'),
},
},
}),
}); |
Beta Was this translation helpful? Give feedback.
-
Any update on this? |
Beta Was this translation helpful? Give feedback.
-
Want to bump this as we're leveraging more monorepo tooling at Disney Streaming and starting to lean into unbuilt internal packages similar to this blog post: https://turborepo.com/posts/you-might-not-need-typescript-project-references. It would be amazing to have a first-class way to tell the compiler to transform files within node_modules if they match a regex (we'd make it match our internal package scope). |
Beta Was this translation helpful? Give feedback.
-
This FR is an anti-pattern. Treat your packages like packages. If you want to speed up your dev workflow, use your workspace manager to |
Beta Was this translation helpful? Give feedback.
-
ICYMI: Next.js 13.1 included built-in transpilation: /** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@acme/ui', 'lodash-es'],
};
module.exports = nextConfig; https://nextjs.org/blog/next-13-1#built-in-module-transpilation-stable |
Beta Was this translation helpful? Give feedback.
-
Now some of us ships NPM packages (specially components) written in ES2015 without transpiling them.
That's a pretty good thing specially if they are gonna used in a project like Next.js or CRA (which does transpiling). They offer benefits like:
But we can't do this now we exclude everything inside node_modules from babel transpiling.
So, here's the proposed solution.
We have an entry in
next.config.js
to include modules which needs to go through babel. See:Beta Was this translation helpful? Give feedback.
All reactions