Tried following the answers in 58613492,59879689 and 61781271
having the following error with jest :
SyntaxError: Cannot use import statement outside a module
1 | import { Lambda, SecretsManager, config as awsConfig } from 'aws-sdk';
> 2 | import axios from 'axios';
As you can see, it only complains about the second line (..?)
using node
v14.19.3
my tsconfig.ts
{
"compilerOptions": {
"target": "es2017",
"allowJs": true,
"module": "commonjs",
"outDir": "dist",
"rootDir": ".",
"importHelpers": true,
"strict": true,
"noImplicitReturns": true ,
"noFallthroughCasesInSwitch": true ,
"moduleResolution": "node",
"baseUrl": "./",
"lib": ["ES2020.Promise"],
"types": ["node", "jest"],
"allowSyntheticDefaultImports": true ,
"esModuleInterop": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
my jest.config.js
module.exports = {
preset: "ts-jest",
transform: {
"^.+\\.(ts|tsx)?$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest",
},
testEnvironment: "node",
testTimeout: 60000,
testPathIgnorePatterns: ["dist/*"],
};
my babel.config.js
module.exports = {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: { esmodules: false, node: 'current' },
},
],
'@babel/preset-flow',
],
plugins: [
['@babel/plugin-transform-modules-commonjs'],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties'],
],
};
package.json
{
"name": "device-job-sender",
"version": "1.0.0",
"description": "",
"main": "src/handlers/job-sender-handler.ts",
"scripts": {
"test": "jest --detectOpenHandles",
"deploy:local": "sls deploy --stage local",
"start:local": "docker-compose down && docker-compose up -d && npm run deploy:local",
"deploy": "./.circleci/deploy.sh",
"prettify": "prettier \"{src,test,scripts}/**/*.{js,ts}\" --write"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vnatures/device-job-sender.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/vnatures/device-job-sender/issues"
},
"homepage": "https://github.com/vnatures/device-job-sender#readme",
"devDependencies": {
"@babel/preset-env": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@types/aws-lambda": "^8.10.79",
"@types/jest": "^26.0.24",
"@types/redis": "^2.8.29",
"babel-loader": "^8.2.2",
"fork-ts-checker-webpack-plugin": "^6.2.12",
"husky": "^7.0.1",
"jest": "^26.6.3",
"ts-jest": "^26.5.6",
"ts-loader": "^8.1.0",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"tslib": "^2.3.0",
"typescript": "^4.2.3",
"webpack": "^4.44.1",
"webpack-node-externals": "^2.5.2"
},
"dependencies": {
"@types/aws-iot-device-sdk": "^2.2.3",
"@vnatures/logger": "^2.0.1",
"@vnatures/secrets-manager": "^2.0.2",
"axios": "^1.3.3"
}
}