martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Transpiled module imports dependency as async when it has a nested dependency with {type: "module"} #242

Closed ewnd9 closed 2 years ago

ewnd9 commented 2 years ago

Are you trying to transpile a local package or an npm package?

Originally caught it with tslib inside dependency graph, minimal repro is below πŸ‘‡

Describe the bug

next.config.js:

module.exports = require('next-transpile-modules')(['a-1', 'a-2'], {
  debug: true,
})();

import graph:

app -> node_modules/a-1 (transpiled) -> node_modules/a-2 (transpiled) -> node_modules/a-3 (not transpiled, `{ "type": "module" }`)

a-2 is treated as async import inside a-1 and returns promise, but importing from the app directly works correctly.

a2 inside node_modules {
  default: Promise {
    <pending>,
    [Symbol(webpack exports)]: Object [Module] {},
    [Symbol(webpack then)]: [Function (anonymous)]
  }
}
a3 inside node_modules [Module: null prototype] {  }
a1 inside src {}
a2 inside src Object [Module] {}

To Reproduce

https://github.com/ewnd9/next-transpile-modules-repro

Expected behavior

Should be treated as static import

Setup

ewnd9 commented 2 years ago

The issue is actually with swc-loader https://github.com/vercel/next.js/issues/30638

Closing this.