As I embark on migrating some node packages, I find myself facing a significant challenge.
Here is the current state of my package.json file:
{
//These are the updated dependencies and Jest configurations
"dependencies": {
"@google-cloud/logging-winston": "^4.0.2",
"@google-cloud/secret-manager": "^3.2.3",
"@google-cloud/storage": "^5.7.0",
...
},
"devDependencies": {
"@nestjs/cli": "^8.1.5",
"@nestjs/schematics": "^8.0.5",
...
},
"jest": {
...
}
}
Upon attempting to run Jest, I encountered an error related to /node_modules
● Test suite failed to run
Jest encountered an unexpected token
...
Details:
/home/{username}/{project_directory}/node_modules/mongodb/src/bson.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import type {
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (../node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (../node_modules/mongodb/src/bson.ts:8:12)
We were able to resolve this issue within our team by making adjustments to the Jest configuration, specifically changing:
"moduleDirectories": [
"node_modules",
"src"
],
To:
"moduleDirectories": [
"node_modules",
],
In addition, we needed to revert back to relative import paths. This solution successfully eliminated the error, but we're curious as to why it works. Any insights?
Thank you!