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

Transpile ESM import #29

Closed
rtritto opened this issue Feb 5, 2023 · 6 comments
Closed

Transpile ESM import #29

rtritto opened this issue Feb 5, 2023 · 6 comments

Comments

@rtritto
Copy link

rtritto commented Feb 5, 2023

Steps to reproduce

  • yarn init -y
  • yarn set version canary
  • yarn add devalue ts-import typescript (devalue is an ESM)
  • Create test.ts file
import 'devalue'
  • Create start.js file
const { loadSync } = require('ts-import')
loadSync('./test.ts')
  • yarn node start.js
    output:
C:\test-esm\.pnp.cjs:5645
        Error.captureStackTrace(err);
              ^

Error: require() of ES Module C:\Users\<USER>\AppData\Local\Yarn\Berry\cache\devalue-npm-4.2.3-7b5bd84f96-9.zip\node_modules\devalue\index.js from C:\test-esm\.cache\ts-import\C\test-esm\test.js not supported.
Instead change the require of index.js in C:\test-esm\.cache\ts-import\C\test-esm\test.js to a dynamic import() which is available in all CommonJS modules.
    at Object.require$$0.Module._extensions..js (C:\test-esm\.pnp.cjs:5645:15)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.require$$0.Module._load (C:\test-esm\.pnp.cjs:5487:14)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\test-esm\.cache\ts-import\C\test-esm\test.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Object.require$$0.Module._extensions..js (C:\test-esm\.pnp.cjs:5649:33)
    at Module.load (node:internal/modules/cjs/loader:1004:32) {
  code: 'ERR_REQUIRE_ESM'
}
@rtritto
Copy link
Author

rtritto commented Feb 13, 2023

Related: microsoft/TypeScript#43329

Possible related/workaround (to check): @brillout/import

@yunsii
Copy link

yunsii commented Mar 20, 2023

Any progress?

@rtritto
Copy link
Author

rtritto commented Mar 22, 2023

I think no, some help is needed

@radarsu
Copy link
Owner

radarsu commented Apr 11, 2023

I'll be looking into that.

@radarsu
Copy link
Owner

radarsu commented Apr 11, 2023

For ESM packages I've released 5.0.0-beta.0 version - fully updated to ESM. My test suite is passing, but it isn't yet battle-tested so use with caution.

@radarsu radarsu closed this as completed Apr 11, 2023
@rtritto
Copy link
Author

rtritto commented Apr 11, 2023

@radarsu same error with [email protected].

start.js:

const { load } = require('ts-import')
load('./test.ts')

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

No branches or pull requests

3 participants