Skip to content

[Bug]: @babel/parser: __esModule property is not defined in lib/index.js since version 7.22.11 #15934

@tkallage

Description

@tkallage

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

working in 7.22.10:
npm i @babel/parser@7.22.10 local-pkg@0.4.3
run in node REPL:

require('local-pkg').importModule('@babel/parser').then(({parse}) => console.log(parse))

Result: [Function: parse]

not working in 7.22.11:
npm i @babel/parser@7.22.11 local-pkg@0.4.3
run in node REPL:

require('local-pkg').importModule('@babel/parser').then(({parse}) => console.log(parse))

Result: undefined

And

require('local-pkg').importModule('@babel/parser').then(({default: {parse}}) => console.log(parse))

Result: [Function: parse]

Configuration file name

No response

Configuration

No response

Current and expected behavior

unplugin-vue-components uses importModule() from the package local-pkg to import @babel/parser.
It recognizes the property __esModule to import the default export of @babel/parser.

With @babel/parser 7.22.10 this works fine, but since 7.22.11 the esModule-marker is missing in the resulting lib/index.js file, resulting in the imported object { default: { parser(), ... } } instead of { parser(), ... }.

Environment

System:
OS: Windows 10 10.0.22621
Binaries:
Node: 18.12.0 - C:\Program Files\nodejs\node.EXE
npm: 9.8.1 - <project_path>\node_modules.bin\npm.CMD
pnpm: 8.5.0 - C:\Program Files\nodejs\pnpm.CMD
npmPackages:
@babel/parser: ^7.22.11 => 7.22.11
@babel/runtime: ^7.22.11 => 7.22.11
eslint: ^8.48.0 => 8.48.0

Possible solution

Add

Object.defineProperty(exports, '__esModule', {
  value: true
});

at the top of the resulting file /lib/index.js in @babel/parser

Additional context

grafik
grafik

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions