node_modules/@nestjs/schematics/dist/lib/resource/files/ts/entities/name@singular.entity.ts breaks NPM commands
See original GitHub issueBug Report
In the last 2 days I noticed an error in my pipeline after npm install, which breaks the whole pipeline from succeeding. The error seems to be caused by a file inside node modules which is interpreted by typescript and failes.
Current behavior
I am using Gitlab pipelines to push the code to a DigitalOcean droplet. After npm install when I try to run migrations, I started to see this error: Error during migration run: backend/dist/node_modules/@nestjs/schematics/dist/lib/resource/files/ts/entities/name@singular.entity.ts:1 <% if (type === ‘graphql-code-first’) { %>import { ObjectType, Field, Int } from ‘@nestjs/graphql’; ^ SyntaxError: Unexpected token ‘<’
The error is replicable only on the Digital Ocean server which operates on Ubuntu 20.04. I cannot replicate it on my machine as the file is not found inside node_modules.
Input Code
The content of the file from node_modules/@nestjs/schematics/dist/lib/resource/files/ts/entities/name@singular.entity.ts:1 is:
<% if (type === 'graphql-code-first') { %>import { ObjectType, Field, Int } from '@nestjs/graphql';
@ObjectType()
export class <%= singular(classify(name)) %> {
@Field(() => Int, { description: 'Example field (placeholder)' })
exampleField: number;
}<% } else { %>export class <%= singular(classify(name)) %> {}<% } %>
</
Expected behavior
This file should either be removed or fixed somehow as the content inside it is clearly not typescript and that`s why it is failing: node_modules/@nestjs/schematics/dist/lib/resource/files/ts/entities/name@singular.entity.ts
Environment
Nest version: 7.0.0
For Tooling issues:
- Node version: node: 12.18.3, npm: 6.14.6
- Platform: Ubuntu 20.04.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:12 (4 by maintainers)
Top GitHub Comments
@Malak67 Looks like it’s an issue when TypeORM tries to load entities from
node_modules
folder. I had the same problem and fixed it by changing theentities
property as shown below: fromentities: [join(__dirname, './**/*.entity{.ts,.js}')]
toentities: [join(__dirname, 'apps/backend/src/**/*.entity{.ts,.js}')]
.Hope this solution matches your case too!
I’ve just published a new
@nestjs/schematics@7.1.2
release which dynamically updates the entity template filename. In this case, even if the wrong glob path is specified in the TypeOrm settings, the template file should be ignored.