Hi, need help. Deploy failed on build, very strange “cors” issue npm ERR! Cannot read property ‘cors’ of undefined. I pressed “clear cache” and deploy, nothing helped. Have no idea.
import express from 'express';
import cors from 'cors';
import { router as productsRouter } from './routes/products';
const router = express.Router();
const port = 5000;
const app = express();
app.use(cors());
"start": "node ./build/server.js",
"build": "npm ci && tsc",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mysql2": "^2.3.3",
"pg-hstore": "^2.3.4",
"react-scripts": "^5.0.1",
"sequelize": "^6.26.0",
"sequelize-typescript": "^2.1.5",
"serverless-http": "^3.1.0",
"uuid": "^9.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
}
Feb 11 07:38:39 PM ==> Downloading cache...
Feb 11 07:38:48 PM ==> Transferred 5.3KB in 7s. Extraction took 0s.
Feb 11 07:38:50 PM ==> Running build command 'npm run build'...
Feb 11 07:38:50 PM
Feb 11 07:38:50 PM > api@1.0.0 build /opt/render/project/src
Feb 11 07:38:50 PM > npm ci && tsc
Feb 11 07:38:50 PM
Feb 11 07:38:50 PM npm ERR! Cannot read property 'cors' of undefined
Feb 11 07:38:50 PM
Feb 11 07:38:50 PM npm ERR! A complete log of this run can be found in:
Feb 11 07:38:50 PM npm ERR! /opt/render/.cache/_logs/2023-02-11T17_38_50_866Z-debug.log
Feb 11 07:38:50 PM npm ERR! code ELIFECYCLE
Feb 11 07:38:50 PM npm ERR! errno 1
Feb 11 07:38:50 PM npm ERR! api@1.0.0 build: `npm ci && tsc`
Feb 11 07:38:50 PM npm ERR! Exit status 1
Feb 11 07:38:50 PM npm ERR!
Feb 11 07:38:50 PM npm ERR! Failed at the api@1.0.0 build script.
Feb 11 07:38:50 PM npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 11 07:38:50 PM
Feb 11 07:38:50 PM npm ERR! A complete log of this run can be found in:
Feb 11 07:38:50 PM npm ERR! /opt/render/.cache/_logs/2023-02-11T17_38_50_898Z-debug.log
Feb 11 07:38:50 PM ==> Build failed 😞
Feb 11 07:38:50 PM ==> Generating container image from build. This may take a few minutes...
UPD. I fixed the problem. After matching node version it was Live from second try.