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

Version 8.0.0 doesn't work #17

Closed
manuth opened this issue Apr 3, 2021 · 4 comments
Closed

Version 8.0.0 doesn't work #17

manuth opened this issue Apr 3, 2021 · 4 comments

Comments

@manuth
Copy link

manuth commented Apr 3, 2021

The most recent version 8.0.0 is not working.
According to the error messages, following imports are malformed:
https://github.com/sindresorhus/read-pkg-up/blob/e6fbe7f1ce52cbfb924543ef0e9801775efc38cc/index.js#L1-L2

I'm facing following message:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: .\node_modules\read-pkg-up\index.js
require() of ES modules is not supported.
require() of .\node_modules\read-pkg-up\index.js from .\lib\tests\Management\DependencyCollection.test.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from .\node_modules\read-pkg-up\package.json.

    at new NodeError (node:internal/errors:329:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (.\lib\tests\Management\DependencyCollection.test.js:15:23)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (.\lib\tests\Management\index.js:14:37)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (.\lib\tests\main.test.js:13:22)      
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:201:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:154:23)
    at async Loader.import (node:internal/modules/esm/loader:166:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async formattedImport (.\node_modules\mocha\lib\esm-utils.js:7:14)
    at async Object.exports.loadFilesAsync (.\node_modules\mocha\lib\esm-utils.js:55:20)
    at async singleRun (.\node_modules\mocha\lib\cli\run-helpers.js:125:3)
    at async Object.exports.handler (.\node_modules\mocha\lib\cli\run.js:362:5)
@sindresorhus
Copy link
Owner

Please read the release notes.

@manuth
Copy link
Author

manuth commented Apr 3, 2021

Awesome! Thanks for your rapid answer

@alvis
Copy link

alvis commented Apr 14, 2021

While I love ESM syntax and I use ESM syntax via typescript, the new ESM only version has an untented consequence that all downstream libraries have to adapt ESM in order to use the lastest version. In my case, I can't use it with typescript anymore since my target is commonjs.

We can still use v7 without the issue, but it'd better if v8 is released as a hybrid npm package with both commonjs & ESM. See How to Create a Hybrid NPM Module for ESM and CommonJS for example.

@Hufschmidt
Copy link

Hufschmidt commented Aug 27, 2021

Same issue as @alvis, this change forces all downstream modules to use ESM and makes typescript transpilation to commonjs impossible!

Edit: Replaced read-pkg-up with https://sami-chkhachkhi.medium.com/import-version-from-package-json-ef47fe505d9d instead.

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

4 participants