Correct way pkg a Next 14 app? #144
Replies: 4 comments 2 replies
-
|
Please share pkg command output with |
Beta Was this translation helpful? Give feedback.
-
|
thanks the build output is huge though doesnt show any errors the end message is [ the output with debug enabled is consistent Node.js v20.18.2 Next 14 uses a next.config.mjs file by default so looks like this is a problem for pkg. Here is my package.json config "bin": "server.js", There are a few articles dotted arounf the internet but I havent found anything current. |
Beta Was this translation helpful? Give feedback.
-
|
i didn't get it to work with Next (way too complex I think), but tried a much simpler test which I think proves the point. pkg doesn't appear to work with imports. ESM is modern node. Do you think pkg will support ESM in the future? |
Beta Was this translation helpful? Give feedback.
-
|
I have noticed this issue while trying to add ESM pnpmfiles support to pnpm: pnpm/pnpm#9730 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to pkg up a Nest 14 app into a windows executable using pkg. Im trying to build an exe out of the default production build (next build) with out using output: export, or output: standalone settings.
===
Pretty standard setup with a minimal custom server to act as my entrypoint
server.js
// Use CommonJS require syntax instead of ES Modules import syntax
const next = require('next');
const http = require('http');
const port = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
console.log('App prepared, starting server...');
const server = http.createServer((req, res) => {
handle(req, res);
});
console.log('Server created, starting to listen...');
server.listen(port, (err) => {
if (err) throw err;
console.log(
> Ready on http://localhost:${port});});
}).catch((err) => {
console.error('Error during app preparation:', err);
});
===
equally simple next.config.mjs
/** @type {import('next').NextConfig} */
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log("webpack __dirname: ", __dirname);
const nextConfig = {
webpack: (config) => {
config.resolve.alias['@common'] = path.resolve(__dirname, "../common");
return config;
},
};
export default nextConfig;
===
and my npm scripts
"scripts": {
"build": "next build",
"build:pkg": "pkg server.js --output nextapp --targets node20-win-x64 -d",
},
"pkg": {
"scripts": [
".next.prod/dist//*.js"
],
"assets": [
".next.prod//*",
"next.config.mjs",
"server.js"
]
},
npm run build:pkg does indeed create an exe but when i run it I get the following error:
PS K:\docker\apps\FoTL_CAM\projects\client\cam-client> .\nextapp.exe
⨯ Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error
Error during app preparation: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:265:9)
at loadConfig (C:\snapshot\FoTL_CAM\node_modules.pnpm\next@14.2.17_@babel+core@7.26.9_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.85.1\node_modules\next\dist\server\config.js:711:78)
at async initialize (C:\snapshot\FoTL_CAM\node_modules.pnpm\next@14.2.17_@babel+core@7.26.9_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.85.1\node_modules\next\dist\server\lib\router-server.js:55:20)
at async NextCustomServer.prepare (C:\snapshot\FoTL_CAM\node_modules.pnpm\next@14.2.17_@babel+core@7.26.9_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.85.1\node_modules\next\dist\server\next.js:242:28) {
code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING'
}
Beta Was this translation helpful? Give feedback.
All reactions