-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
import.meta.dirname + import.meta.filename undefined
in page
#60879
Comments
cc @alexander-akait if I should open an issue in https://github.com/webpack/webpack, let me know and I'll do that. |
@karlhorky Yeah, to be honestly it is already in my internal roadmap 😄 |
Ok, then I'll just leave it open here. |
WorkaroundConfigure the /** @type {import("next").NextConfig} */
const nextConfig = {
reactStrictMode: true,
webpack: (
config,
{ buildId, dev, isServer, defaultLoaders, nextRuntime, webpack },
) => {
config.plugins.push(
new webpack.DefinePlugin({
"import.meta.dirname": "__dirname",
}),
);
return config;
},
};
export default nextConfig; CodeSandbox demo: https://codesandbox.io/p/devbox/import-meta-dirname-reproduction-forked-4ldmgw?file=%2Fnext.config.js%3A3%2C25 |
@alexander-akait let us know when it's landed in webpack, would love to help bump webpack in next.js for this later 🙏 |
undefined
in page
I just upgraded to Node 20, used How hard would it be to add @karlhorky’s workaround in the meantime? |
Looks like turbopack does not know about And because webpack config is ignored by |
@alexander-akait if you haven't gotten around to implementing yet, what do you think about me creating a tracking issue in the webpack repo? |
Ah wait, looks like there maybe is one already...? Looks like the issue started as some other topic, but now is about general |
@karlhorky Yeah, it is an issue about it |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/import-meta-dirname-reproduction-vj3gfq?file=%2Fapp%2Fpage.tsx%3A1%2C1
To Reproduce
import.meta.dirname
isundefined
in the webpack-compiledpage.tsx
(but is a dir path in Node.js)Changes to repro template:
"type": "module"
to enable running ESM with Node.js (and changemodule.exports =
toexport default
innext.config.js
)import-meta.dirname.js
withconsole.log()
ofimport.meta.dirname
console.log()
ofimport.meta.dirname
toapp/page.tsx
Current vs. Expected behavior
I expected
import.meta.dirname
andimport.meta.filename
, introduced in Node.js 20.11.0 to not beundefined
in Next.js pages in the App Router, but it isundefined
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Binaries: Node: 20.11.0 npm: 10.2.4 Yarn: 1.22.19 pnpm: 8.14.1 Relevant Packages: next: 14.1.1-canary.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Module resolution (CJS / ESM, module resolving)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
No response
PACK-2953
The text was updated successfully, but these errors were encountered: