Skip to content

Jest: "Cannot use import statement outside a module" when importing use-query-params/adapters/react-router-6 #224

@marhaupe

Description

@marhaupe

Using [email protected], when importing use-query-params/adapters/react-router-6 in a jest test running with ts-jest and TypeScript's moduleResolution set to node, we see the following error:

Cannot use import statement outside a module

I believe this is because the copy-adapters.js script in use-query-params/scripts does not copy the package.json of the respective adapter. I monkey-patched the node_modules the following way, and it did the trick:

use-query-params/
├─ adapters/
│  ├─ react-router-6/
│  │  ├─ dist/
│  │  │  ├─ index.cjs.js
│  │  │  ├─ index.js
│  │  │  ├─ index.d.ts
│  │  ├─ package.json

I see that you've deliberately excluded the package.json from the copy-adapters script though, so maybe I'm not seeing something:

if (buildFile !== 'package.json') {

Let me know if you would be open to a pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions