-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
need help building example, esmregister + esmock #788
need help building example, esmregister + esmock #788
Comments
Fixed in #798 |
The specific error described at the top of this issue is resolved, however, after updating ✖ should mock js when using swc (34.125566ms)
file:///home/bumble/soft/esmock/tests/local/mainUtil.js:2
import babelGeneratedDoubleDefault from 'babelGeneratedDoubleDefault';
^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: The requested module 'babelGeneratedDoubleDefault' does not provide an export named 'default' The error needs context to be understood but, essentially, Slightly difficult to describe the sequence resulting in the error, here is what happens,
The other loaders used in the test suite process the same import tree without error https://github.com/iambumblehead/esmock/tree/attempt-enable-swc-tests/tests Thank you for reading me |
I've tried tsx, it's also throw a error: // index.ts
import assert from 'node:assert'
import test from 'node:test'
import babelGeneratedDoubleDefault from './babel-generated-double-default'
await test('import default from babel-generated cjs file', () => {
assert.equal(babelGeneratedDoubleDefault(), 'default.default')
})
|
git clone https://github.com/iambumblehead/esm-import-cjs-repro.git
cd esm-import-cjs-repro
npm install
npm run test:node # pass
npm run test:tsx # pass
npm run test:swc # fail |
@iambumblehead this failed because of the peerDependencies are missing, you need to install |
after adding $ cat package.json | grep dependencies -A 6
"dependencies": {
"babelGeneratedDoubleDefault": "file:./babelGeneratedDoubleDefault",
"typescript": "^5.5.3",
"@swc-node/register": "1.10.2",
"@swc/core": "^1.6.13",
"tsx": "^4.15.5"
},
$ npm install
added 2 packages, and audited 28 packages in 34s
6 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
$ npm run test:swc
> [email protected] test:swc
> node --import @swc-node/register/esm-register --test test.swc.test.ts
✖ should import babelGeneratedDoubleDefault, cjs deep (12.353619ms)
file:///home/bumble/soft/esm-import-cjs-repro/src/esmmain2.js:1
import babelGeneratedDoubleDefault from 'babelGeneratedDoubleDefault'; |
the first test, importing mixed esm cjs tree passes, but the second test encounters a runtime error, test('should mock ts when using swc', async () => {
const main = await esmock('../local/main-ts.ts', {
path: {
basename: () => 'hellow'
}
})
assert.strictEqual(main.pathbasenamewrap(), 'hellow')
}) The error occurs when the typescript file "main-ts.ts" is loaded. test at esmock.node-swc.test.ts:15:1
✖ should mock ts when using swc (5.206873ms)
SyntaxError [Error]: Unexpected token ':' main-ts.ts, link import path from 'path'
import pg from 'pg'
export default {
pathbasenamewrap: (n: any) => path.basename(n),
pgpoolwrap: (n: any) => pg.Pool(n)
} If the typescript |
the error happens when esmock is engaged to load the ts file the same test using esmock passes when using node-ts, tsx or tsm |
At esm-import-cjs-repro, the test is added for tsx and swc and the error is reproduced using swc
|
related #710 |
all tests pass :) |
When trying to create an example test with swc and esmock, this error occurs around the types definition file,
Thanks in advance for any advice
The text was updated successfully, but these errors were encountered: