Git Product home page Git Product logo

Comments (4)

wooorm avatar wooorm commented on July 22, 2024 1

done!

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024

Well, this is internals...

from import-meta-resolve.

IronGeek avatar IronGeek commented on July 22, 2024

I kinda figure it out... I guess this issue a bit of an edge cases...

  1. You need to be using Node v22.
  2. You need to be using pnpm.
    Tested with npm and pnpm. The deprecation warning is not shown with npm. I guess its related to how pnpm treats and resolve transitive dependencies (see point 3, below).
  3. You need to be using a babel presets or plugins that are not directly added as dependency

For example, running:

pnpm add -D @babel/cli @babel/core @babel/preset-env
touch index.js
pnpm exec babel index.js -d out --presets=@babel/preset-env --plugins=@babel/plugin-transform-class-properties

will result in success (kinda) but with a warning.:

(node:279128) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Successfully compiled 1 file with Babel (416ms).

While installing the dependencies using npm and running with npx will result in:

npx babel index.js -d out --presets=@babel/preset-env --plugins=@babel/plugin-transform-class-properties
Successfully compiled 1 file with Babel (327ms).

Both commands are using the @babel/plugin-transform-class-properties plugin, a transitive dependency from @babel/preset-env. While NPM can resolve it just fine, pnpm can't.

But, if we try to use a preset or a plugin that are not installed at all; like @babel/preset-react for example, both pnpm and npm will result in error:

pnpm exec babel index.js -d out --presets=@babel/preset-env,@babel/preset-react --plugins=@babel/plugin-transform-class-properties
(node:280601) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error: Cannot find package '@babel/preset-react' imported from <REDACTED>/babel-virtual-resolve-base.js
    at __node_internal_ (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:224:9)
    at new NodeError (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:194:5)
    at packageResolve (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:908:9)
    at moduleResolve (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:937:20)
    at defaultResolve (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:1007:15)
    at resolve (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:1020:12)
    at tryImportMetaResolve (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/config/files/plugins.js:142:45)
    at resolveStandardizedNameForImport (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/config/files/plugins.js:164:19)
    at resolveStandardizedName (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/config/files/plugins.js:173:22)
    at loadPreset (<REDACTED>/node_modules/.pnpm/@[email protected]/node_modules/@babel/core/lib/config/files/plugins.js:61:20)
    at loadPreset.next (<anonymous>)
...
npx babel index.js -d out --presets=@babel/preset-env,@babel/preset-react --plugins=@babel/plugin-transform-class-properties
(node:280117) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error: Cannot find package '@babel/preset-react' imported from <REDACTED>/babel-virtual-resolve-base.js
    at __node_internal_ (<REDACTED>/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:224:9)
    at new NodeError (<REDACTED>/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:194:5)
    at packageResolve (<REDACTED>/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:908:9)
    at moduleResolve (<REDACTED>/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:937:20)
    at defaultResolve (<REDACTED>/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:1007:15)
    at resolve (<REDACTED>/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:1020:12)
    at tryImportMetaResolve (<REDACTED>/node_modules/@babel/core/lib/config/files/plugins.js:142:45)
    at resolveStandardizedNameForImport (<REDACTED>/node_modules/@babel/core/lib/config/files/plugins.js:164:19)
    at resolveStandardizedName (<REDACTED>/node_modules/@babel/core/lib/config/files/plugins.js:173:22)
    at loadPreset (<REDACTED>/node_modules/@babel/core/lib/config/files/plugins.js:61:20)
    at loadPreset.next (<anonymous>)
...

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024

This is happening here on Node 22. You can run the tests and see it.

from import-meta-resolve.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.