serverless-bundle
serverless-bundle copied to clipboard
Error when importing node-fetch
When testing a file that imports "node-fetch", I get the jest error regarding imports (other test files in the same project that don't import node-fetch are fine):
● Test suite failed to run
Jest encountered an unexpected token
...snip...
Details:
C:\Work\Source\datacloud-listener\node_modules\node-fetch\src\index.js:9
import http from 'node:http';
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import fetch, { Headers, Request, Response } from "node-fetch";
| ^
2 |
3 | if (!global.fetch) {
4 | global.fetch = fetch;
at Runtime.createScriptFromCode (node_modules/jest-runner/node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (src/fetch-polyfill.js:1:1)
Any idea what the cause of this or how to work around it?
I'm experiencing this issue as well. The code runs fine, but not in tests. It doesn't seem like jest is being run with the same configuration.
I don't know what to do. None of the transform/transformIgnorePatterns inscructions on stackoverlfow seem to do anything.