-
Notifications
You must be signed in to change notification settings - Fork 167
Description
I am running the command yarn open-next build --config-path ./apps/app01/open-next.config.ts
, but I get the following error in the console:
node:fs:448
return binding.readFileUtf8(path, stringToFlags(options.flag));
^
Error: ENOENT: no such file or directory, open '/home/jarod/Documentos/development/FKW/aion/dist/apps/app01/.next/.open-next/.build/open-next.config.mjs'
at readFileSync (node:fs:448:20)
at initOutputDir (file:///home/jarod/Documentos/development/FKW/aion/node_modules/open-next/dist/build.js:138:28)
at build (file:///home/jarod/Documentos/development/FKW/aion/node_modules/open-next/dist/build.js:43:5)
at async file:///home/jarod/Documentos/development/FKW/aion/node_modules/open-next/dist/index.js:9:1 {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/home/jarod/Documentos/development/FKW/aion/dist/apps/app01/.next/.open-next/.build/open-next.config.mjs'
}
Next itself builds normally.
My project is a monorepo with NX, Next.js, and open-next.
"dependencies": {
"next": "14.2.3",
"open-next": "^3.0.6",
"react": "18.3.1",
"react-dom": "18.3.1",
"tslib": "^2.3.0"
},
Content of the open-next.config.ts configuration file:
import type { OpenNextConfig } from 'open-next/types/open-next';
const config = {
appPath: 'apps/app01',
buildCommand: 'yarn nx build app01 --verbose',
buildOutputPath: 'dist/apps/app01/.next',
default: {},
} satisfies OpenNextConfig;
export default config;
The function initTempDir is creating the config file in the monorepo root:
Ok, analyzing the library, I noticed that in the function initOutputDir
, it takes the tempDir
from the options normalized by the normalizeOptions
function. However, the problem is that it sets this tempDir
as a folder already inside the build folder, whereas the initial tempDir
created by the initTempDir
function at the beginning of the build points to the root of the monorepo. This causes a break because the initOutputDir
function expects this file and tempDir
to exist inside the build folder, which they don't. At no point is this file moved to the build folder.
In summary, the folder .open-next/.build
does not exist within the build files, which was to be expected.
I managed to build it after manually modifying the initOutputDir
function in the library like this:
function initOutputDir(tempDir) {
const { outputDir, tempDir: lTempDir } = options;
const openNextConfig = readFileSync(path.join(tempDir, "open-next.config.mjs"), "utf8");
let openNextConfigEdge = null;
if (fs.existsSync(path.join(tempDir, "open-next.config.edge.mjs"))) {
openNextConfigEdge = readFileSync(path.join(tempDir, "open-next.config.edge.mjs"), "utf8");
}
fs.rmSync(outputDir, { recursive: true, force: true });
fs.mkdirSync(lTempDir, { recursive: true });
fs.writeFileSync(path.join(lTempDir, "open-next.config.mjs"), openNextConfig);
if (openNextConfigEdge) {
fs.writeFileSync(path.join(tempDir, "open-next.config.edge.mjs"), openNextConfigEdge);
}
}
In which the tempDir
passed as a parameter is the tempDir
created by the initTempDir
function, which points to the root of the monorepo.
I wanted to know if there is any official solution :/