-
Notifications
You must be signed in to change notification settings - Fork 26k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEXT-1255] transpilePackages does not support hooks in pnpm linked modules #50391
Comments
We're seeing a similar issue with our internal component library, although we don't use pnpm. When we actually publish the component library everything works fine. I created a repro with a similar setup over here: To reproduce the issue, execute these commands:
Remember to re-link when switching between Next versions, I use this: I added both a "pages" page (the homepage) and an "app" page ("about"). We've been seeing this issue since version 13.3.2, and it's still there in the latest canary |
I have a strong feeling this is actually a node module resolutions issue related to how Next vendors React. I had some similar problems in E2E testing the
^^ Yeah this is it. |
To clarify, we're also seeing this when not using the app directory at all. I just added it in the repro as an example. |
We have been seeing the same thing, with a bare-bones NextJS repo (pages only, no app dir) and Yarn with linked packages. 13.3.1 seems fine, going to 13.3.2 then breaks. |
Hey @shuding , if this is being worked on at the moment, any chance for an ETA as to when a patch would be deployed? A bit stuck on an upcoming release because of it. Thank you! |
Hi @altechzilla I’ve added this to the maintainer’s tracker so this can get prioritized, but it’s still in queue and we don’t have an ETA yet. |
Thank you! |
Hey @shuding - I know the Next team is working hard on the app router performance issues, but I was just wondering if we have any update on this yet. Thank you! |
@shuding Any updates on this? Thank you! |
I read on the blog that lots of bugs around the stability of the App Router had been tackled, but this is still not working over here, with version 13.4.8 |
Hey @shuding is the Next.js team still on this? Major roadblock because of this bug. |
Hey @altechzilla, we haven't been able to prioritize fixing this over other bugs that many more people are running into (i.e. more 👍, more comments, etc.). It will be worked on eventually as it's in our issue tracker but I can't give an estimate right now as we're focusing on solve the largest issues people have. |
@altechzilla If this is critical for your work, I would recommend contributing directly to Next.js, that will be harder but faster to get this issue solved. @timneutkens can the Next.is team provide some code pointers for those willing to help? |
Hey @timneutkens @martpie - Eventually, I managed to rebuild the modules that were preventing us from migrating the remaining routes to the app directory. So, I just wanted to give you guys a heads-up that this issue is no longer a high priority for me. Thanks! |
This issue happens when linked library use react hooks. This error appear to me after next 13.3.1 So this error appear because
Finally i found a solution by forcing alias of react to node_module/react inside my nextjs project. I added following nextjs config: //next.config.js
// @ts-check
/**
* @typedef {import('next').NextConfig} NextConfig
* @typedef {import('webpack').Configuration} WebpackConfig
* @typedef {import('next/dist/server/config-shared').WebpackConfigContext} WebpackConfigContext
* @typedef {(config: WebpackConfig, context: WebpackConfigContext) => any} NextWebpackConfig
*/
const nextConfig = async () => {
/**
*
* @param {import('webpack').Configuration} config
* @param {import('next/dist/server/config-shared').WebpackConfigContext} _context
* @returns {import('webpack').Configuration}
*/
webpack: (config, _context) => {
config.resolve.alias['react'] = path.resolve(__dirname, 'node_modules/react')
return config;
},
}
module.exports = nextConfig; This issue is maybe related to |
This issue happened to us after we migrated our monorepo to use
I tried using
|
Any update...? @ali4heydari Thanks I finally found solution to transpilePackages.....🥲 const path = require('path');
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@tanstack/react-query', '@tanstack/query-core'],
webpack(webpackConfig) {
webpackConfig.resolve.alias["@tanstack/react-query"] = path.resolve(
__dirname,
"./node_modules/@tanstack/react-query"
);
webpackConfig.resolve.alias["@tanstack/query-core"] = path.resolve(
__dirname,
"./node_modules/@tanstack/query-core"
);
return {
...webpackConfig,
}
},
}
module.exports = nextConfig |
We also just completely switched to the App Router, so we're not seeing this issue anymore either :) |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 Binaries: Node: 20.2.0 npm: 9.6.6 Yarn: N/A pnpm: 8.4.0 Relevant packages: next: 13.4.4 eslint-config-next: 13.4.4 react: 18.2.0 react-dom: 18.2.0 typescript: 5.0.4
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
N/A
To Reproduce
pnpm link --global
inside of a third party modulepnpm link module_name
to link it to your projectTypeError: Cannot read properties of null (reading 'useState')
This entire process works in appDir OR with @martpie 's deprecated package.
Describe the Bug
This issue only affects the pages directory, not the app directory.
Ever since @martpie 's next transpile modules package was deprecated, we moved to the new built-in solution. The main project is
pnpm link
-ed to a bunch of external ESM modules that we use to share packages between projects.When linked, the transpiler does not process hooks correctly.
TypeError: Cannot read properties of null (reading 'useState')
- this error throws up regardless of the hook being used (useState, useRef, useEffect, etc.)However, if you do NOT pnpm link the modules, it works. Previously we used the
{ resolveSymlinks: false }
option in @martpie 's package, but this doesn't seem to be available or relevant to the built-in solution.Therefore, the only way we can use the transpilePackages feature is with appDir. But since we do have some routes that need to stay in pages dir, we're a bit stuck.
Expected Behavior
It should allow hooks to fire as usual.
Which browser are you using? (if relevant)
Any
How are you deploying your application? (if relevant)
Localhost
NEXT-1255
The text was updated successfully, but these errors were encountered: