Dynamically import JSON will fail in production mode #63233
Unanswered
ChiuMungZitAlexander
asked this question in
Help
Replies: 1 comment
-
I had to install the json-loader plugin and add a rule to the next.config to deal with json files differently for some specific paths and now it works as intended. Example: config.module.rules.push({
test: /\.json$/,
type: 'javascript/auto',
use: 'json-loader',
include: pathToSpecificFiles
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Inside a route handler
/api/route.ts
, I want to import different JSON files by the environment variables. I did as belowThis is working perfectly in dev mode (
next dev
). Also, the project can be compiled successfully(next build
).However, when running production(
next start
), this JSON will be an empty object{}
. It will NOT throw any error of path resolving or else.I also tried using assertion as below, but got the same result.
Even though I solved it as below, I wonder why
await import
will fail.Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions