Skip to content

Unable to detect exports from bundled webpack output聽#88

Open

Description

@SimenB

Title is probably inaccurate 馃槄

I recently added bundling to Jest, and it seems the output makes the lexer not detect exports correctly.

Specifically, it picks up the exports. stuff that is not exported, but not the exports within Object.definedProperty which actually are.

Quickest reproduction I have is to clone Jest, run yarn && yarn build:js then this:

const fs = require('fs');
const {parse} = require('cjs-module-lexer');

const source = fs.readFileSync(require.resolve('jest-watcher'), 'utf8');

console.log(parse(source));

This prints

{
  exports: [
    'default',
    'KEYS',
    'printPatternCaret',
    'printRestoredPatternCaret'
  ],
  reexports: []
}

Running the parser on the published version (29.7.0) gives this:

{
  exports: [
    '__esModule',
    'BaseWatchPlugin',
    'JestHook',
    'PatternPrompt',
    'Prompt',
    'TestWatcher'
  ],
  reexports: [ './constants', './lib/patternModeHelpers' ]
}

The reexports are of course gone as it's bundled, but we're also seeing that the lexer has detected only the resolved re-exports?

Activity

  1. liuxingbaoyu commented on Oct 9, 2023

    @liuxingbaoyu

    https://github.com/nodejs/cjs-module-lexer#project-status This project has been frozen, I suspect webpack may have relevant options that will follow this.

  2. SimenB commented on Oct 9, 2023

    @SimenB
    MemberAuthor

    Yeah, I noticed that.

    Would be cool if we can configure webpack to output compatible code, yeah. Might have to create a manual re-export facade thing if not.

    Or just accept interop is not the best and have people use default export.

  3. liuxingbaoyu commented on Oct 9, 2023

    @liuxingbaoyu

    webpack/webpack#13098
    rollup/rollup#4826

    Unfortunately webpack doesn't support this, although rollup does.

  4. SimenB commented on Oct 9, 2023

    @SimenB
    MemberAuthor

    Happy to switch to rollup (vite probably?) instead - I'm not particularly married to using webpack (it's just the one I got working (and the one I have by far the most experience with))

  5. SimenB commented on Oct 30, 2023

    @SimenB
    MemberAuthor

    FWIW, I think I'll just be checking the exports manually at build time and include an mjs file, which should skip the lexer entirely: jestjs/jest#14661

  6. liuxingbaoyu commented on Oct 31, 2023

    @liuxingbaoyu

    Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions