Skip to content

Error: No valid exports main found for '/path/to/nanoid' #215

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

Closed
cansin opened this issue May 2, 2020 · 20 comments · Fixed by #216
Closed

Error: No valid exports main found for '/path/to/nanoid' #215

cansin opened this issue May 2, 2020 · 20 comments · Fixed by #216

Comments

@cansin
Copy link
Contributor

cansin commented May 2, 2020

As initially described at #206 (comment) , I am getting a MODULE_NOT_FOUND error with node@13.2.0 and yarn@1.22.4.

Here is the repro: https://github.com/cansin/nanoid-module-not-found-repro

And a sample run on my local:

cansin@localhost nanoid-repro % node --version
v13.2.0
cansin@localhost nanoid-repro % yarn --version
1.22.4
cansin@localhost nanoid-repro % yarn install
yarn install v1.22.4
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
[3/5] 🚚  Fetching packages...
[4/5] 🔗  Linking dependencies...
[5/5] 🔨  Building fresh packages...

✨  Done in 0.09s.
cansin@localhost nanoid-repro % node index.js 
internal/modules/cjs/loader.js:614
  throw e;
  ^

Error: No valid exports main found for '/Users/cansin/code/nanoid-reprod/node_modules/nanoid'
    at resolveExportsTarget (internal/modules/cjs/loader.js:611:9)
    at applyExports (internal/modules/cjs/loader.js:492:14)
    at resolveExports (internal/modules/cjs/loader.js:541:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:643:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:941:27)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (/Users/cansin/code/nanoid-reprod/index.js:1:20)
    at Module._compile (internal/modules/cjs/loader.js:1121:30) {
  code: 'MODULE_NOT_FOUND'
}

Thanks.

@TrySound
Copy link

TrySound commented May 2, 2020

Now, try to upgrade node.

@cansin
Copy link
Contributor Author

cansin commented May 2, 2020

Btw, either upgrading to the latest Node, or even downgrading to LTS 12.16.3 fixes this issue. So perhaps it is not related to the library. But still, you might want to update your engines.node to a valid list.

@cansin
Copy link
Contributor Author

cansin commented May 2, 2020

@TrySound see above ^ 😊

@ai
Copy link
Owner

ai commented May 2, 2020

Thanks for the repo. I will take a look today or tomorrow.

@marcelo-michels
Copy link

I was having the same problem using NodeJS 13. I followed the recommendations to go back to NodeJS 12 and it worked. But soon I intend to use it with NodeJS 13.

@TrySound
Copy link

TrySound commented May 4, 2020

@marcelo-michels The latest node 13 should work fine. The problem happens only with early versions.

@ai
Copy link
Owner

ai commented May 4, 2020

@cansin sorry, we do not support old versions of Node.js 13, because they have problems with ESM.

You should update to the latest Node.js 13 version.

@ai ai closed this as completed May 4, 2020
@ai
Copy link
Owner

ai commented May 4, 2020

I added note about old Node.js 13 versions to Migration Guide https://github.com/ai/nanoid/releases/tag/3.0.0

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

Sure yeah I already did that. I still suggest you to update your engines.node so that any unsupported node version would complain. Obvs. your call.

@ai
Copy link
Owner

ai commented May 4, 2020

@cansin we support Node.js 10 and 12. Do you have an idea of how to specify engine, to avoid old Node.js 13 versions?

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

e.g. Let's say >= 13.3 works. I believe something like:

"engines": {
  "node": "^10 || ^12 || >=13.3"
}

would work.

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

i.e. it follows the regular semver rules ( https://docs.npmjs.com/files/package.json#dependencies ).

@ai
Copy link
Owner

ai commented May 4, 2020

@cansin we also need to add >= 14 to the list.

Do you want to send PR to save your name in the project history?

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

I think >=13.3 would cover >=14. Sure, let me send a PR once I figure out which 13.x versions are failing.

@ai
Copy link
Owner

ai commented May 4, 2020

I think >=13.3 would cover >=14.

You are right 😅

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

Ok at 13.7 it runs with a warning:

(node:23723) ExperimentalWarning: Conditional exports is an experimental feature. This feature could change at any time

I will draw the line there.

@ai
Copy link
Owner

ai commented May 4, 2020

The warning is OK

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

@ai any reason why we don't support ^11 ?

@ai
Copy link
Owner

ai commented May 4, 2020

Because 11 is not supported by Node.js https://nodejs.org/en/about/releases/

@cansin
Copy link
Contributor Author

cansin commented May 4, 2020

Ah, right. Makes sense

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

Successfully merging a pull request may close this issue.

4 participants