简体   繁体   中英

Next.js app with both Javascript and Typescript

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?

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';

Adding to tsconfig.json

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

Resolved this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM