Running npm run makemigrations throws 'Cannot find module '@entity''
See original GitHub issueVersion of FoalTS: 2.6.0
When I try to run the npm run makemigrations
command, if I have some imports in my entities that use the @entity
it throws this error:
Error during migration generation: Error: Cannot find module ‘@entity’
This is the makemigrations
command (should be the default one) : foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate --name migration && tsc -p tsconfig.app.json
and this is my tsconfig.app.json
:
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts"
],
"exclude": [
"src/e2e/*.ts",
"src/**/*.spec.ts",
"src/e2e.ts",
"src/test.ts"
]
}
tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "build", /* Redirect output structure to the directory. */
"strict": true, /* Enable all strict type-checking options. */
"strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"noImplicitAny": false,
"target": "ES2021",
"resolveJsonModule": true,
"rootDir": "src",
"lib": [
"ES2021"
],
"baseUrl": "src",
"paths": {
"@lib": ["lib"],
"@entity": ["app/entities"],
"@service": ["app/services"],
"@interface": ["app/interfaces"],
"@hook": ["app/hooks"],
"@middleware": ["app/middleware"]
}
},
"include": [
"src/**/*.ts",
"ormconfig.js",
"config/*.js"
]
}
and package.json
:
"_moduleAliases": {
"@service": "build/app/services",
"@entity": "build/app/entities",
"@interface": "build/app/interfaces",
"@hook": "build/app/hooks",
"@middleware": "build/app/middleware",
"@lib": "build/lib",
"@dbconfig": "build/ormconfig.js"
},
It works fine if I import using from './'
but I want to know why it’s not working with import { ... } from '@entity'
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
TypeOrm migration - Error: Cannot find module - Stack Overflow
Now I'm getting the error: RepositoryNotFoundError: No repository for "permissions" was found. Looks like this entity is not registered in ...
Read more >cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >cannot find module 'path' or its corresponding type declarations
To solve the "Cannot find module `path` or its corresponding type declarations" error, install the types for node by running the command `npm...
Read more >Building a REST API with NestJS and Prisma
With the Prisma schema defined, you will run migrations to create the ... throwing an exception that says: Error: Cannot find module '....
Read more >Migrations - typeorm - GitBook
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm" ... This command will execute all pending migrations and run them in a sequence ordered...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, so the problem probably comes from here.
When running the application, the
index.ts
file is read at first and so themodule-alias
module is registered.But in the case of the migrations, this file is not read. Only the migration files and the files they import are. This is probably why you get this error.
Could the commands
npx typeorm -r module-alias/register migration:run
ornode -r module-alias/register ./node_modules/.bin/typeorm migration:run
fix the problem? Or something similar?Glad that you found how to fix the issue! I’d rather not to add it to the documentation as I feel like it is a specific issue related to the use of a 3rd-part library (module-alias). If anyone has the same problem, he or she will be able to find the solution on this issue. 🙂