I’m getting the following error when building for production. Here’s the output of npm run build
running on Node v16.20.1
npm run build
> [email protected] build
> vite build
vite v4.4.9 building SSR bundle for production...
✓ 123 modules transformed.
node:internal/event_target:1011
process.nextTick(() => { throw err; });
^
file:///Users/luca/Projects/personal/fpv-finder/.svelte-kit/output/server/chunks/runtime.esm.js:3
import { IntlMessageFormat } from "intl-messageformat";
^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'IntlMessageFormat' not found. The requested module 'intl-messageformat' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'intl-messageformat';
const { IntlMessageFormat } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async analyse (file:///Users/luca/Projects/personal/fpv-finder/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:60:16)
at async MessagePort.<anonymous> (file:///Users/luca/Projects/personal/fpv-finder/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
Emitted 'error' event on Worker instance at:
at Worker.[kOnErrorMessage] (node:internal/worker:298:10)
at Worker.[kOnMessage] (node:internal/worker:309:37)
at MessagePort.<anonymous> (node:internal/worker:205:57)
at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:736:20)
at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
And this is the code generated that is causing the issue.
import { d as derived, w as writable } from "./index.js";
import deepmerge from "deepmerge";
import { IntlMessageFormat } from "intl-messageformat"; // <- This is the issue
function delve(obj, fullKey) {
if (fullKey == null)
return void 0;
if (fullKey in obj) {
return obj[fullKey];
}
// [...] Other code here
Is there a way I can fix this?
And here’s the package.json
{
"name": "fpv-finder",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-netlify": "^2.0.8",
"@sveltejs/kit": "^1.25.1",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"autoprefixer": "^10.4.16",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.33.2",
"postcss": "^8.4.30",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"svelte": "^4.2.1",
"svelte-check": "^3.5.2",
"tailwindcss": "^3.3.3",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.4.9"
},
"type": "module",
"dependencies": {
"svelte-i18n": "^3.7.4"
}
}
The step I’ve done are just running npm run build
and I was expecting the project to be built.
2
Answers
Okay I found a way on how to solve this. First step I took was running
I saw that
intl-messageformat
wasn't the latest version. So I added that dependency in the package.json.Ran
npm install
and thennpm run build
. Problem solved.Basically I did the same thing that was suggested in the comments.
There is an
svelte-i18n
issue with module resolution that happens with some Kit adapters.A workaround appears to be to install a newer version of
intl-messageformat
.You could also downgrade
svelte-i18n
.