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

feat: transform module dependencies #17

Closed
privatenumber opened this issue Apr 9, 2021 · 2 comments
Closed

feat: transform module dependencies #17

privatenumber opened this issue Apr 9, 2021 · 2 comments
Labels

Comments

@privatenumber
Copy link
Contributor

privatenumber commented Apr 9, 2021

I'd like to request that esbuild-register applies transformations to ESM dependencies. It currently can't import packages with type: 'module' (unless the current project is also ESM):

> esno src/index.ts

internal/modules/cjs/loader.js:1080
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /node-project/node_modules/.pnpm/vue-ast-utils@1.0.1_@vue+compiler-core@3.0.11/node_modules/vue-ast-utils/dist/index.js
require() of ES modules is not supported.
require() of /node-project/node_modules/.pnpm/vue-ast-utils@1.0.1_@vue+compiler-core@3.0.11/node_modules/vue-ast-utils/dist/index.js from /node-project/src/lib/selector/index.ts 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-project/node_modules/.pnpm/vue-ast-utils@1.0.1_@vue+compiler-core@3.0.11/node_modules/vue-ast-utils/package.json.

    at Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Object.newLoader [as .js] (/node-project/node_modules/.pnpm/esbuild-register@2.4.0/node_modules/esbuild-register/dist/node.js:2262:9)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/node-project/src/lib/selector/index.ts:2:27)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._compile (/node-project/node_modules/.pnpm/esbuild-register@2.4.0/node_modules/esbuild-register/dist/node.js:2258:26)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
  code: 'ERR_REQUIRE_ESM'
}

I think this problem will be become more common in the near future due to sindresorhus/meta#15.

This is similar to #12, but I cannot add type: 'module' because I'm only using esbuild-register in development but building to CJS for production.

Similar issue from esm: standard-things/esm#868

@privatenumber privatenumber changed the title feat: transform dependencies feat: transform module dependencies Apr 10, 2021
@deleonio
Copy link

Bugs by using mocha and esbuild-register - with OpenAPI generator.

image

The problem is transpiling node_modules too. (with babel-register there was a option and it works)

@egoist egoist closed this as completed in a540af7 Apr 18, 2021
@egoist
Copy link
Owner

egoist commented Apr 18, 2021

🎉 This issue has been resolved in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants