I've been encountering an issue with building a Nextjs application since yesterday without making any changes at this level. Even after reverting the changes, the error persists.
Is there anyone who can assist me with this problem?
./node_modules/typeorm/browser/index.js
Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (3:0)
You may need an appropriate loader to handle this file type, as currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| /*!
| */
> import "reflect-metadata";
| // -------------------------------------------------------------------------
| // Commonly Used exports
Import trace for requested module:
./node_modules/typeorm/index.mjs
This is my package.json:
- Although I have some babel dependencies, I don't have a .babelrc file configured. It was used for loader testing as the error message suggests, but it didn't resolve the issue.
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"test": "jest --setupFiles=dotenv/config",
"lint": "eslint pages --ext .ts,.tsx"
},
"dependencies": {
...
},
"devDependencies": {
...
},
"version": "0.0.0"
}
This is my tsconfig.json:
{
"compilerOptions": {
...
},
"include": [
...
],
"exclude": [
...
]
}
Additionally, I am importing typeorm, not typeorm/browser as depicted below:
import { User } from '@/entities/User'
import 'reflect-metadata'
import { Connection, createConnection } from 'typeorm'
export async function initializeDatabase () {
return new Promise<Connection>((resolve, reject) => {
createConnection({
...
}).then(connection => {
...
}).catch(error => {
...
})
})
}