My project is failing to import a local package that I linked even though I have verified that it was successfully installed through yarn list --pattern @packagename
.
Whenever I try to run yarn start, I get the error:
TSError: тип Unable to compile TypeScript:
src/controllers/geoCode/getGeoCode.ts:5:29 - error TS2307: Cannot find module '@packrat/packages' or its corresponding type declarations.
And whenever I hover my mouse over the import path, it tells me :
Cannot find module '@packrat/packages' or its corresponding type declarations
This is how I import it:
import * as validators from '@packrat/packages';
Running yarn list --pattern @packrat/packages
returns the package and the version successfully.
Package.json file of @packrat/packages
{
"name": "@packrat/packages",
"version": "0.0.1",
"source": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "NODE_OPTIONS=--max_old_space_size=4096 tsc",
"build:and:install": "yarn build && yarn"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/express": "^4.17.17",
"@types/node": "^20.8.3",
"express": "^4.18.2",
"typescript": "^5.2.2",
"zod": "^3.22.2"
}
}
package.json file of lib I'm trying to use it in:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"build": "NODE_OPTIONS=--max_old_space_size=4096 tsc",
"debug": "cross-env NODE_OPTIONS='--inspect-brk' nodemon",
"dev": "nodemon",
"lint": "eslint . --fix --ext .ts",
"setup": "echo \"No setup needed\"",
"start:pm2": "pm2 start dist/index.js --name server",
"start:prod": "node dist/index.js",
"start:ts-node": "ts-node src/index.ts",
"start": "nodemon",
"test:expect": "mocha 'generated/test/**/*.spec.js'",
"test:generate": "npx openapi-generator url http://localhost:3000/swagger.json -d ./generated -t javascript",
"test": "echo \"No tests yet\""
},
"author": "Andrew Bierman",
"license": "ISC",
"dependencies": {
"@hono/node-server": "^1.2.0",
"@hono/trpc-server": "^0.1.0",
"@packrat/packages": "*",
"@sendgrid/mail": "^7.7.0",
"@trpc/client": "^10.38.5",
"@trpc/server": "^10.38.5",
"@types/bcrypt": "^5.0.0",
"@types/cors": "^2.8.13",
"@types/csurf": "^1.11.2",
"@types/mongoose": "^5.11.97",
"@types/node": "^20.8.3",
"@types/swagger-jsdoc": "^6.0.1",
"@types/swagger-ui-express": "^4.1.3",
"@types/validator": "^13.11.1",
"axios": "^1.4.0",
"bcrypt": "^5.1.0",
"body-parser": "^1.20.2",
"bull": "^4.10.4",
"celebrate": "^15.0.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
"csurf": "^1.11.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-rate-limit": "^6.9.0",
"firebase": "^9.19.1",
"firebase-admin": "^11.5.0",
"google-auth-library": "^8.8.0",
"googleapis": "^118.0.0",
"helmet": "^7.0.0",
"hono": "^3.8.0",
"i": "^0.3.7",
"joi": "^17.9.2",
"jsonwebtoken": "^9.0.1",
"mongoose": "^7.4.0",
"mongoose-autopopulate": "^1.0.1",
"mongoose-to-swagger": "^1.4.0",
"morgan": "^1.10.0",
"node-fetch": "^3.3.1",
"nodemailer": "^6.9.1",
"nodemailer-smtp-transport": "^2.7.4",
"nodemon": "^3.0.1",
"openai": "^3.3.0",
"osmtogeojson": "^3.0.0-beta.5",
"passport": "^0.6.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"piscina": "^4.0.0",
"superjson": "^2.0.0",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^4.6.3",
"trpc-panel": "^1.3.4",
"typescript": "^5.2.2",
"uuid": "^9.0.0",
"validator": "^13.9.0",
"zod": "^3.22.2"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.7.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"cross-env": "^7.0.3",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^38.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.0.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"expect.js": "^0.3.1",
"jest": "^29.6.2",
"migrate-mongo": "^10.0.0",
"mocha": "^10.2.0",
"openapi-generator": "^0.1.39",
"prettier": "^3.0.2",
"ts-node": "^10.9.1"
},
"engines": {
"node": ">=16.0.0"
},
"jest": {
"testMatch": [
"<rootDir>/generated/test/**/*.[jt]s?(x)",
"<rootDir>/generated/test/?(*.)+(spec|test).[jt]s?(x)"
]
}
}
I have checked my node modules and I see the package there but still unable to import.
I deleted my node_modules folder and reinstalled it again(yarn install
), yet didn't work.
When I deleted my yarn.lock file and tried to add it back using yarn import
, I get this warning for some packages including the one causing the above error:
warning Import of "[email protected]" for "packrat-world" failed, resolving normally.
warning Import of "[email protected]" for "packrat-world" failed, resolving normally.
warning Import of "@packrat/[email protected]" for "packrat-world" failed, resolving normally.
warning Import of "check-dependency-version-consistency@^4.1.0" for "packrat-world" failed, resolving normally.
warning Import of "@manypkg/cli@^0.21.0" for "packrat-world" failed, resolving normally.
warning Import of "[email protected]" for "packrat-world" failed, resolving normally.
warning Import of "cross-env@^7.0.3" for "packrat-world" failed, resolving normally.
warning Import of "husky@^8.0.0" for "packrat-world" failed, resolving normally.
warning Import of "dotenv-cli@^7.3.0" for "packrat-world" failed, resolving normally.
warning Import of "lint-staged@^14.0.1" for "packrat-world" failed, resolving normally.
warning Import of "typescript@^5.2.2" for "packrat-world" failed, resolving normally.
error An unexpected error occurred: "https://registry.yarnpkg.com/@packrat%2fpackages: Not found".
It seems the error is due to my yarn.lock not able to import it, but I don't know how exactly to solve it
EDIT: Just to note, I'm a newbie in yarn. This project wasn't set up by me, so any suggestions no matter how stupid would help.