I literally made no changes to code, and suddenly I woke up to this error one day,
backend: internal/modules/cjs/loader.js:454
backend: const e = new Error(`Package exports for '${basePath}' do not define a ` +
backend: ^
backend: Error: Package exports for '/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/tslib' do not define a valid '.' target
backend: at resolveExportsTarget (internal/modules/cjs/loader.js:454:13)
backend: at resolveExports (internal/modules/cjs/loader.js:387:16)
backend: at Function.Module._findPath (internal/modules/cjs/loader.js:486:20)
backend: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:781:27)
backend: at Function.Module._load (internal/modules/cjs/loader.js:687:27)
backend: at Module.require (internal/modules/cjs/loader.js:849:19)
backend: at require (internal/modules/cjs/helpers.js:74:18)
backend: at Object.<anonymous> (/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/apollo-link/lib/index.js:3:15)
backend: at Module._compile (internal/modules/cjs/loader.js:956:30)
backend: at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) {
backend: code: 'MODULE_NOT_FOUND'
backend: }
backend: [nodemon] app crashed - waiting for file changes before starting...
This person from another StackOverflow question changed their node version and it worked for them, I tried it too (v12.x.x -> v15.x.x), didn't work for me.
I also upgraded typescript
, tried installing tslib
, did yarn cache clean
, deleted and reinstalled node_modules, deleted yarn.lock
, nothing worked.
Please help.
Here's my package.json
:
{
"name": "backend",
"version": "1.0.0",
"license": "ISC",
"main": "dist/src/index.js",
"scripts": {
"build": "tsc -p tsconfig.release.json",
"build:watch": "tsc --watch -p tsconfig.release.json",
"start": "npm run build && node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node dist/src/index.js",
"start:pm2": "NODE_ENV=production pm2 start dist/src/index.js --node-args=\"--max_old_space_size=500 --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node\"",
"dev": "npm run build && concurrently --raw \"nodemon --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node dist/src/index.js\" \"npm run build:watch\"",
"lint": "eslint . --ext js,jsx,ts,tsx",
"lint:fix": "eslint . --fix --ext js,jsx,ts,tsx",
"test": "NODE_ENV=test jest --passWithNoTests --watch",
"test:ci": "NODE_ENV=test jest --passWithNoTests"
},
"devDependencies": {
"@types/bull": "^3.14.0",
"@types/mongoose": "^5.5.43",
"@types/node": "^12.7.3",
"@types/node-cron": "^2.0.2",
"@types/nodemailer": "^6.4.0",
"concurrently": "^5.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-typescript-prettier": "^2.1.0",
"nodemon": "^1.19.1",
"pm2": "^4.4.0",
"prettier": "^1.18.2",
"tslib": "^2.0.3",
"typescript": "^3.7.0",
"typings": "^2.1.1"
},
"dependencies": {
...
"tslib": "^2.0.3",
...
},
"engines": {
"node": ">=12.x"
},
"resolutions": {
"graphql": "14.x"
}
}
Here's my tsconfig.json
:
{
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowJs": true,
"importHelpers": true,
"alwaysStrict": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
// "lib": ["es2017"],
"types": ["jest"]
},
"include": ["src/**/*", "__tests__/**/*"],
"paths": {
"tslib" : ["node_modules/tslib/tslib.d.ts"]
},
}
Here's my tsconfig.release.json
:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist",
"removeComments": true
},
"include": ["src/**/*"]
}
Thanks!
For me, these steps did the trick:
NodeJS
stable version: nvm install --lts
/node_modules
& package-lock.json
filespm2 kill
and pm2 start process.json
The trick was actually killing pm2 and adding the process again. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With