Skip to content
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

Module not found: Default condition should be the last one #955

Open
liztanyulin opened this issue Nov 12, 2023 · 1 comment
Open

Module not found: Default condition should be the last one #955

liztanyulin opened this issue Nov 12, 2023 · 1 comment

Comments

@liztanyulin
Copy link

I'm trying to use this library in a NextJS app but I'm facing this issue where it says Module not found: Default condition should be the last one. I didn't see this problem anywhere else in the app until I wrote this api page which calls contentful-import.

Screenshot 2023-11-12 at 10 39 22 AM

I came across a similar issue reported with Firebase so I tried rolling back to earlier versions, but I have not been able to get this to work so far.

I was using Node v16.20.1 and then v20.9.0. Below is my package.json if it helps:

{
  "name": "contentful-migration",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "contentful": "^10.6.4",
    "contentful-export": "^7.8.16",
    "contentful-import": "^9.4.10",
    "next": "13.5.6",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-query": "^3.39.3"
  },
  "devDependencies": {
    "@types/node": "20.8.8",
    "@types/react": "18.2.31",
    "@types/react-dom": "18.2.14",
    "eslint": "8.52.0",
    "eslint-config-next": "13.5.6",
    "typescript": "5.2.2"
  }
}

Any help is appreciated 🙏🏼 Thank you

@aghuddleston
Copy link
Contributor

I also came across this issue. I'm using contentful-import in a github action that is using @vercel/ncc and the error I am getting is Error: Module not found: Error: Default condition should be last one

ncc: Compiling file index.js into CJS
Error: Module not found: Error: Default condition should be last one
Did you mean './contentful-import'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

The order of the exports section of package.json just needs to be updated to put default as the last one.

"exports": {
    "default": "./dist/index.js",
    "require": "./dist/index.js",
    "import": "./dist/index.mjs",
    "node": "./dist/index.js"
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants