I have this schema in file data.ts
import mongoose from "mongoose";
const Schema = mongoose.Schema;
const DataSchema = new Schema(
{
id: Number,
message: String,
},
{ timestamps: true }
);
module.exports = mongoose.model('Data', DataSchema);
When I try to import this in my index.js as :
const Data = require('./data');
I keep seeing this error:
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module './data'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
Any ideas why this is.
I've tried doing:
export const data = mongoose.model('Data', DataSchema);
then importing with import { data as Data } from './data'
But that also returns the following error:
import { data as Data } from './data'
^
SyntaxError: Unexpected token {
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)

data.tstypescript file which you are importing inindex.jsjavascript file? O_oindex.tsfile?node index.tsindex.jsfile to run your program.