Error importing rdfjs with jest
Closed this issue · 3 comments
I'm running into a problem using rdfjs types together with the jest testing framework. The jest resolver can't find "@rdfjs/types" when it's imported in some library. When I edit the @rdfjs/types/package.json
file adding "main" : "index.d.ts"
, it can then find the package but it throws an error when importing the relative imports within that package.
Disclaimer: I'm not super experienced with typescript.
The error I am running into is:
➜ npm test
> minimal-rdfjs-jest@1.0.0 test
> node --experimental-vm-modules node_modules/jest/bin/jest.js
FAIL src/index.test.ts
● Test suite failed to run
Cannot find module '@rdfjs/types' from 'src/index.ts'
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
I uploaded a minimal example to reproduce here: https://github.com/MMesch/minimal-rdfjs-jest
Any ideas what could cause this and how to fix or workaround?
Importing other packages seems to work fine (I added chalk
in the example to demonstrate).
No code exists in the package @rdfjs/types
. Try type-only import
import type * as rdfjs from '@rdfjs/types';
Great that works! Thank you very much for the quick help.
I exchanged: import {type Quad, type ResultStream} from '@rdfjs/types';
with import type {Quad, ResultStream} from '@rdfjs/types';
and that did the trick.
I was extra confused because building, the language server and everything else worked well otherwise. Only jest bugged.