You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read Caveats documentation and didn't find a solution for this problem there.
Bug description
When using with node:test, node is unable to import the library. It looks like this might be a tsc configuration issue.
> test
> node --test --trace-warnings
TAP version 13
# Subtest: /path/to/index.test.js
not ok 1 - /path/to/index.test.js
---
duration_ms: 0.040726583
failureType: 'subtestsFailed'
exitCode: 1
stdout: ''
stderr: |-
(node:99872) ExperimentalWarning: The test runner is an experimental feature. This feature could change at any time
at emitExperimentalWarning (node:internal/util:226:11)
at node:test:5:1
at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/loaders:331:7)
at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/loaders:269:10)
at loadBuiltinModule (node:internal/modules/cjs/helpers:50:9)
at ESMLoader.builtinStrategy (node:internal/modules/esm/translators:258:18)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:470:14)
file:///path/to/index.test.js:3
import { mockClient } from 'aws-sdk-client-mock'
^^^^^^^^^^
SyntaxError: Named export 'mockClient' not found. The requested module 'aws-sdk-client-mock' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'aws-sdk-client-mock';
const { mockClient } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
Node.js v18.8.0
error: 'test failed'
code: 'ERR_TEST_FAILURE'
...
1..1
# tests 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.063401583
Updating to use import pkg from 'aws-sdk-client-mock'; const { mockClient } = pkg;, returns the following:
> test
> node --test --trace-warnings
TAP version 13
# Subtest: /paht/to/index.test.js
not ok 1 - /path/to/index.test.js
---
duration_ms: 0.044459167
failureType: 'subtestsFailed'
exitCode: 1
stdout: ''
stderr: |-
(node:835) ExperimentalWarning: The test runner is an experimental feature. This feature could change at any time
at emitExperimentalWarning (node:internal/util:226:11)
at node:test:5:1
at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/loaders:331:7)
at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/loaders:269:10)
at loadBuiltinModule (node:internal/modules/cjs/helpers:50:9)
at ESMLoader.builtinStrategy (node:internal/modules/esm/translators:258:18)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:470:14)
(node:835) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/path/to/node_modules/aws-sdk-client-mock/dist/es/index.js:1
export * from './mockClient';
^^^^^^
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1048:15)
at Module._compile (node:internal/modules/cjs/loader:1083:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
Node.js v18.8.0
error: 'test failed'
code: 'ERR_TEST_FAILURE'
...
1..1
# tests 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.0666855
Lib provides both CJS and ESM files. Here it seems the Node chooses to use the CJS version and then complains it's not ESM...
I don't have an idea right now for how to fix this and I will be off for most of next month, but I'm happy to review a PR if someone has an idea for this.
Checklist
Bug description
When using with
node:test
, node is unable to import the library. It looks like this might be atsc
configuration issue.Updating to use
import pkg from 'aws-sdk-client-mock'; const { mockClient } = pkg;
, returns the following:Reproduction
package.json
index.test.js
Environment
The text was updated successfully, but these errors were encountered: