i can start my node app fine on my local machine but if i then pull the project from github on my server and start it with npm start i get this error:
Cannot find module '../models/user'.
import User = require('../models/user');
registrationController.ts is trying to access the models/user.
This is how i import in that file:
import User = require('../models/user');
This is my folder structure. I get the error in the highlighted file:

This is my npm start script:
"scripts": {
"start": "nodemon --watch '*.ts' --exec 'ts-node' app.ts"
}
This isn't the correct syntax to use your user model into the controllers, you should assign the required model directly to a variable (either a const or var) as follow:
const User = require('../models/user');
This link has great details regarding the two ways (import and require).
It looks like mixing the es6 syntax with older syntax
use this way if you are exporting that module as a default export
import User from '../models/user';
otherwise use
const User = require('../models/user')
make sure you are exporting the module like this
module.exports = <Your Module>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With