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

[Bug]: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'. #4187

Open
FreePhoenix888 opened this issue Jul 15, 2023 · 1 comment

Comments

@FreePhoenix888
Copy link

Version

29.1.1 (latest)

Steps to reproduce

  1. git clone https://github.com/deep-foundation/npm-automation.git
  2. cd npm-automation
  3. git checkout 89153a08e34165a7b4d27730c295cdfd38c0c097
  4. npm clean-intall
  5. npm run test --templateNamePattern "sync"
  6. See this error:
freephoenix888@freephoenix888:~/Programming/deep/npm-automation$ npm run test --templateNamePattern "sync"

> @deep-foundation/npm-automation@3.2.1 test
> jest sync

 FAIL  __tests__/sync-dependencies.ts
   Test suite failed to run

    src/sync-dependencies.ts:31:82 - error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.

    31   const {default: deepJson}: {default: Package} = await import(deepJsonFilePath, {assert: {type: 'json'}}) ;
                                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~
    src/sync-dependencies.ts:33:97 - error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.

    33   const {default: packageJson}: {default: Partial<PackageJson>} = await import(packageJsonPath, {assert: {type: 'json'}});
                                                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.14 s
Ran all test suites matching /sync/i.

Expected behavior

I expect tests to run without this error

Actual behavior

Tests run with this error

Debug log

freephoenix888@freephoenix888:~/Programming/deep/npm-automation$ export TS_JEST_LOG=ts-jest.log && npm run test --templateNamePattern "sync"

> @deep-foundation/[email protected] test
> jest sync

 FAIL  __tests__/sync-dependencies.ts
  ● Test suite failed to run

    src/sync-dependencies.ts:31:82 - error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.

    31   const {default: deepJson}: {default: Package} = await import(deepJsonFilePath, {assert: {type: 'json'}}) ;
                                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~
    src/sync-dependencies.ts:33:97 - error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.

    33   const {default: packageJson}: {default: Partial<PackageJson>} = await import(packageJsonPath, {assert: {type: 'json'}});
                                                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.187 s
Ran all test suites matching /sync/i.

Additional context

No response

Environment

System:
    OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
  npmPackages:
    jest: ^29.6.1 => 29.6.1
@tlaziuk
Copy link

tlaziuk commented Aug 11, 2023

I think I have encountered a related issue:

> ###@1.9.0 test
> node --no-warnings=ExperimentalWarning --experimental-import-meta-resolve --loader ts-node/esm/transpile-only --max-old-space-size=8192 ./node_modules/jest/bin/jest.js formsection

 FAIL   ###  packages/guidebook-widget/src/components/GuidebookModal/FormView/FormSection/FormSection.spec.tsx
  ● Test suite failed to run

    packages/guidebook-widget/src/components/GuidebookModal/FormView/FormSection/FormSection.tsx:29:68 - error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.

    29 import translations from '../../../../config/translations/de.json' assert { type: 'json' }
                                                                          ~~~~~~~~~~~~~~~~~~~~~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        8.535 s

(I've used # to replace confidential data)

ESM is used all across the project (the package type is module).

  System:
    OS: Linux 5.14 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 20.5.0 - /usr/bin/node
    Yarn: 1.22.15 - /usr/bin/yarn
    npm: 9.8.0 - /usr/bin/npm
  npmPackages:
    jest: ^29.0.0 => 29.6.2 

I'm also attaching the Jest config and resolver and the tsconfig.

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

No branches or pull requests

2 participants