question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Package path ./generated is not exported from package

See original GitHub issue

I have this issue with the generated file in Next JS


wait  - compiling / (client and server)...
error - ./src/pages/index.tsx:9:0
Module not found: Package path ./generated is not exported from package D:\MyWeb\iyansr.id-reborn\node_modules\contentlayer (see exports field in D:\MyWeb\iyansr.id-reborn\node_modules\contentlayer\package.json)
   7 | import { GetStaticProps } from 'next'
   8 | import SectionThree from '@components/SectionThree'
>  9 | import { allBlogs } from 'contentlayer/generated'
  10 |
  11 | const Home = ({ blogPosts }: { blogPosts: any }) => {
  12 |  console.log(blogPosts)

https://nextjs.org/docs/messages/module-not-found

index.js file


//...
import { allBlogs } from 'contentlayer/generated'

const Home = ({ blogPosts }: { blogPosts: any }) => {
	console.log(blogPosts)
	return (
	// ...
	)
}

export const getStaticProps: GetStaticProps = async () => {
	const blogPosts = allBlogs

	return {
		props: {
			blogPosts,
		},
		revalidate: 60 * 60,
	}
}

export default Home

packages installed

"dependencies": {
    "@mdx-js/loader": "^2.1.1",
    "@mdx-js/react": "^2.1.1",
    "@tailwindcss/aspect-ratio": "^0.4.0",
    "@tailwindcss/line-clamp": "^0.3.1",
    "axios": "^0.26.1",
    "contentlayer": "^0.2.5",
    "date-fns": "^2.28.0",
    "disqus-react": "^1.1.2",
    "framer-motion": "^6.3.0",
    "googleapis": "^100.0.0",
    "highlight.js": "^11.5.1",
    "marked": "^4.0.14",
    "next": "12.1.5",
    "next-contentlayer": "^0.2.5",
    "node-sass": "^7.0.1",
    "nprogress": "^0.2.0",
    "qs": "^6.10.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-medium-image-zoom": "^4.3.7",
    "react-modal": "^3.14.4",
    "reading-time": "^1.5.0",
    "sass": "^1.50.0",
    "tailwindcss": "^3.0.24"
  },
  "devDependencies": {
    "@types/marked": "^4.0.3",
    "@types/mdx-js__react": "^1.5.5",
    "@types/node": "^17.0.24",
    "@types/nprogress": "^0.2.0",
    "@types/qs": "^6.9.7",
    "@types/react": "^18.0.5",
    "@types/react-modal": "^3.13.1",
    "@types/sanitize-html": "^2.6.2",
    "autoprefixer": "^10.4.4",
    "globby": "^13.1.1",
    "postcss": "^8.4.12",
    "prettier": "^2.6.2",
    "rehype-autolink-headings": "^6.1.1",
    "rehype-code-titles": "^1.0.3",
    "rehype-prism-plus": "^1.4.0",
    "rehype-slug": "^5.0.1",
    "remark-gfm": "^3.0.1",
    "typescript": "^4.6.3",
    "webpack": "^5.1.0"
  }

tsconfig file

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": [
        "src/components/*"
      ],
      "@utils/*": [
        "src/utils/*"
      ],
      "@assets/*": [
        "src/assets/*"
      ],
      "@styles/*": [
        "src/styles/*"
      ],
      "@content/*": [
        "src/content/*"
      ],
      "@customType/*": [
        "src/types/*"
      ],
      "contentlayer/generated": ["./.contentlayer/generated"]
    },
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "custom.d.ts",
    "src/utils/gtag.js",
    ".contentlayer/generated"
  ]
}

Steps to reproduce :

how to reproduce:

yarn dev http://localhost:8300/

page build stops with the above mentioned error

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bartoszkrawczyk2commented, Sep 6, 2022

Ok, for anyone having the same issue, include this in your tsconfig

"baseUrl": "."
0reactions
iyansrcommented, Sep 6, 2022

@schickling sorry for reaaally long reply this is the repo: https://github.com/iyansr/iyansr.id-reborn

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Package path . is not exported from ...
is not exported from package C:\Users\Sairam\Visual Code\todo-list\node_modules\firebase (see exports field in C:\Users\Sairam\Visual Code\todo ...
Read more >
Module not found: Error: Package path . is not ... - GitHub
This is a problem with that package - it needs to correctly define exports for non-node environments. you already opened an issue there,...
Read more >
module not found: error: package path . is not ... - You.com
I was building a react project but when I tried to run it. It showed the following error: Module not found: Error: Package...
Read more >
Module not found: Error: Package path . is not exported from ...
The issue here was that webpack was referencing the "firebase" from node_modules, rather than from my firebase.ts. And that's why it threw that...
Read more >
r/react icon - Reddit
Having an unusual react-router-dom issue - "Package path ./unstable-native-dependencies is not exported from package".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found