Home > OS >  Next.js app with both Javascript and Typescript
Next.js app with both Javascript and Typescript

Time:10-20

I have a Next.js app written in Javascript, and planning on starting to write new code in Typescript. I tried adding Typescript to the project by running touch tsconfig.json at the project root And

npm install --save-dev typescript @types/react @types/node

And when I try to run npm run dev I get an error

error - ./pages/_app.js:6:0
Module not found: Can't resolve 'src/assets/styles/index.scss'

And pretty much all modules cannot be imported.

What do I need to configure in order to work with both Javascript and Typescript?

CodePudding user response:

Stopping and restarting the server should fix most of your module import issues.

SCSS should be ready to go but if it continues after the restart, declaring it in a typescript declaration file should resolve it.

// index.d.ts
declare module '*.scss';

CodePudding user response:

Adding to tsconfig.json

"compilerOptions": {
    ...
    "baseUrl": ".",
    ...
}

Resolved this

  • Related