-
Notifications
You must be signed in to change notification settings - Fork 11
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
ConfigReadError: Cannot find module '.../compiled-contentlayer-config-xxxxx.mjs' #17
Comments
Updates: Upon investigation, I found that the following code is causing an issue: import * as path from "node:path";
const pathOne = "/Users/rakesh/Projects/x/y";
const pathTwo =
"../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-7XUGISBK.mjs";
const joined = path.join(pathOne, pathTwo.replace("../", "./"));
console.log({ joined });
// {
// joined: "/Users/rakesh/Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-7XUGISBK.mjs",
// } I am not sure why second path resolves prepending "../../../../" to three folders before the current working directory, but it is causing the issue for me. Temporary FixI have temporarily made a fix in my package.json
I hope it is helpful, and someone will create a fix soon. |
➕ Having the same issue sporadically on builds. |
Thanks for the bug report, will look into it |
Hi @rakeshtembhurne, I am running on Mac OS Sonoma 14.5 as well but I am not able to replicate the example and it does not seem to be the same problem as the issue you linked. You are suggesting that the issue is with
I am not sure why there's a const outfilePath = pipe(Object.keys(result.metafile.outputs),
console.log(result.metafile.outputs),
... I want to see where the entrypoint for the file is coming from, thanks. |
@fsansalvadore I took a look at your patch in the supabase repo. It appears similar but seems different from the above case as well. let modifiedContent = data.replace('../../../../', '../../../') It looks like in a monorepo setup the path might be wrong? |
@timlrx I placed console.logs like below in file // Deriving the exact outfilePath here since it's suffixed with a hash
console.log("Metadata Output", JSON.stringify(result.metafile.outputs, null, 2));
const outfilePath = pipe(Object.keys(result.metafile.outputs),
// Will look like `path.join(cacheDir, 'compiled-contentlayer-config-[SOME_HASH].mjs')
Array.find((_) => _.match(/compiled-contentlayer-config-.+.mjs$/) !== null),
(response) => {
console.log("PIPE DATA", response);
return response;
},
// Needs to be absolute path for ESM import to work
O.map((_) => path.join(cwd, _.replace("../", "./"))), O.map(unknownToAbsolutePosixFilePath), O.getUnsafe); Here is the terminal ouput: ▲ Next.js 14.2.3
- Local: https://localhost:3000
- Environments: .env.local, .env
✓ Starting...
Metadata Output {
"../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-66FTXOAZ.mjs.map": {
"imports": [],
"exports": [],
"inputs": {},
"bytes": 8119
},
"../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-66FTXOAZ.mjs": {
"imports": [
{
"path": "contentlayer2/source-files",
"kind": "import-statement",
"external": true
},
{
"path": "rehype-autolink-headings",
"kind": "import-statement",
"external": true
},
{
"path": "rehype-pretty-code",
"kind": "import-statement",
"external": true
},
{
"path": "rehype-slug",
"kind": "import-statement",
"external": true
},
{
"path": "remark-gfm",
"kind": "import-statement",
"external": true
},
{
"path": "unist-util-visit",
"kind": "import-statement",
"external": true
}
],
"exports": [
"Author",
"Doc",
"Guide",
"Page",
"Post",
"default"
],
"entryPoint": "contentlayer.config.ts",
"inputs": {
"contentlayer.config.ts": {
"bytesInOutput": 4313
}
},
"bytes": 4501
}
}
PIPE DATA Some {
value: '../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-66FTXOAZ.mjs',
_tag: 'Some'
}
Metadata Output {
"../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-66FTXOAZ.mjs.map": {
"imports": [],
"exports": [],
"inputs": {},
"bytes": 8119
},
"../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-66FTXOAZ.mjs": {
"imports": [
{
"path": "contentlayer2/source-files",
"kind": "import-statement",
"external": true
},
{
"path": "rehype-autolink-headings",
"kind": "import-statement",
"external": true
},
{
"path": "rehype-pretty-code",
"kind": "import-statement",
"external": true
},
{
"path": "rehype-slug",
"kind": "import-statement",
"external": true
},
{
"path": "remark-gfm",
"kind": "import-statement",
"external": true
},
{
"path": "unist-util-visit",
"kind": "import-statement",
"external": true
}
],
"exports": [
"Author",
"Doc",
"Guide",
"Page",
"Post",
"default"
],
"entryPoint": "contentlayer.config.ts",
"inputs": {
"contentlayer.config.ts": {
"bytesInOutput": 4313
}
},
"bytes": 4501
}
}
PIPE DATA Some {
value: '../../../../Projects/x/y/.contentlayer/.cache/v0.4.3/compiled-contentlayer-config-66FTXOAZ.mjs',
_tag: 'Some'
}
Contentlayer config change detected. Updating type definitions and data...
Generated 20 documents in .contentlayer
✓ Ready in 2.6s |
@rakeshtembhurne thanks! Strange that it includes |
I encountered the same problem (macOS Ventura 13.6.7). I found I was accessing the source directory via a symlink with a different path depth than the direct path. The issue went away when I accessed the underlying directory without using the symlink. |
Getting cannot find module errors, twice when running
npm run dev
as well as while building.Please note how path changes from
/Users/rakesh/Projects
to/Users/Projects
for the compiled .mjs file in above lines. It indicates something might be wrong while calculating the file path.The issue is long pending since contentlayer version > 0.3.1. Here is the unsolved same issue on old repo.
My Configs
OS: Mac OS Sonoma 14.5
Node: v20.13.1
NPM: v10.9.0
Yarn: 1.22.22
"contentlayer2": "^0.4.6",
"next-contentlayer2": "^0.4.6",
"next": "14.2.3",
Replicating the issue
Create a project with Next Saas Stripe Starter. All the config files are present and seem to be correct.
Step 1: Create Repo
npx create-next-app my-saas-project --example "https://github.com/mickasmt/next-saas-stripe-starter"
Step 2: Create Env file with dummy content
cp .env.example .env.local
Step 3: Run the project
Run
npm run dev
oryarn dev
Error will be shown on the terminal.
The text was updated successfully, but these errors were encountered: