I'm facing some challenges with the development of a typescript library npm package. The problem arises when I attempt to import node-fetch for fetch calls. To illustrate my issue, I have set up a sample git repository.
These are the commands I used to reach this stage:
npm i --save-dev typescript ts-node jest @types/jest ts-jest
jest --init
npm i node-fetch
In my package.json, I configured it as follows:
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"/dist"
],
"scripts": {
"test": "jest --coverage",
},
In my tsconfig.json, here is the configuration:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"declaration": true,
"outDir": "./dist"
},
"include": ["src/**/*"]
}
The content of my jest.config.js is:
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
transformIgnorePatterns: ["/node_modules/"],
};
Upon running npm text
, I receive the following result:
> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d797e61646f4d3d233c233d">[email protected]</a> test > jest --coverage FAIL tests/unit/index.test.ts ● Test suite failed to run Jest encountered an unexpected token [Additional details about Jest error] Does anyone have any suggestions? How can I successfully integrate node-fetch into my Typescript project?</p> <p>Edit 1: By installing <a href="https://github.com/sindresorhus/got" rel="nofollow noreferrer">Got</a> using the command <code>npm i got
, I encounter the same error.Edit 2: Included the content of the jest.config.js file