francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
102 stars 24 forks source link

"SyntaxError: Cannot use import statement outside a module" error in Sveltekit apps #109

Closed JoschiZ closed 1 year ago

JoschiZ commented 1 year ago

Hey,

if you try to run this in a sveltekit application you get the error "SyntaxError: Cannot use import statement outside a module".

To reproduce it:

npm create svelte@latest my-app
cd my-app
npm install
npm install mongoose
npm install mongoose-tsgen

Create src/models/test.ts

import mongoose, { Schema } from "mongoose";

const customSchema = new Schema({
    name: String
})

export const MyModel = mongoose.model("Custom", customSchema)

run npx mtgen

The default package.json already sets "type":"module"

francescov1 commented 1 year ago

Hi @JoschiGrey ,

This is not a problem with mongoose-tsgen, rather with your environment which is not allowing for import statements. I dont have any experience with sveltekit so I dont think I can help much, sorry about that!

Closing this off, but feel free to re-open if you think necessary.