While developing the backend of my app with Nest.js and TypeScript, I encountered an issue when attempting to build the project using docker-compose. The error message displayed was as follows:
/app/src/users/users.entity.ts:1
backend_1 | import { Entity, PrimaryGeneratedColumn, Column, BeforeInsert } from 'typeorm';
backend_1 | ^^^^^^
backend_1 |
backend_1 | SyntaxError: Cannot use import statement outside a module
backend_1 | at internalCompileFunction (node:internal/vm:76:18)
...
I also provided my tsconfig file for reference:
{
"compilerOptions": {
...
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
In case it helps, here is the Dockerfile I am using:
FROM node:18
# Install wait-for-it
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /usr/bin/wait-for-it
RUN chmod +x /usr/bin/wait-for-it
...
Although I came across a solution for a similar problem that involves an 'ormconfig' file, I couldn't locate any such file in my project directory.