无法构建下一个.js带有打字稿和 sass 的应用程序



好吧,我已经制作了我的第一个Next.js应用程序,但我遇到了部署问题。我不确定到底是什么原因导致了这个问题,我不得不更新服务器上的节点版本,也许这把事情搞砸了,但这是我的问题。我能跑";npm运行构建";通常在我的windows电脑上,但在ubuntu服务器上失败了。它抛出以下错误:

Global CSS cannot be imported from files other than your Custom <App>. Please move all global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Read more: https://err.sh/next.js/css-global
Location: pages/_app.tsx

所以,据我所知,它抱怨我没有在_app.js中导入css,因为它不理解_app.tsx是同一回事,就像构建脚本不理解typescript一样?或者可能是sass加载程序的某种问题?

这是我的.app.tsx:

import { GlobalStoreProvider } from '../mptools/Store/GlobalStoreProvider'
import en from '../util/locale/en'
import hr from '../util/locale/hr'
import { LocaleProvider } from '../util/locale/NikolicaLocaleContext'
import './style.scss'
function MyApp({ Component, pageProps }) {
return (
<LocaleProvider languages={{ hr, en }} initialLanguage="en">
<GlobalStoreProvider>
<Component {...pageProps} />
</GlobalStoreProvider>
</LocaleProvider>
)
}
export default MyApp

这是我的包.json:

{
"name": "nikolica-apartments",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 8881"
},
"dependencies": {
"@types/nodemailer": "^6.4.0",
"lodash": "^4.17.20",
"next": "9.5.5",
"node-sass": "^4.14.1",
"nodemailer": "^6.4.14",
"react": "16.13.1",
"react-dom": "16.13.1"
},
"devDependencies": {
"@types/node": "^14.11.8",
"@types/react": "^16.9.52",
"babel-plugin-import": "^1.13.1",
"babel-plugin-inline-react-svg": "^1.1.1",
"babel-plugin-lodash": "^3.3.4",
"typescript": "^4.0.3"
}
}

运行node-vnode sass-v和tsc-v命令表明这三个命令都已安装(分别为12.19.0、4.14.1和4.0.5(。我不知道如何调试它。我已经删除了我的node_modules和package-lock.json;npm i";但同样的问题仍然存在。

编辑:还有,这是tsconfig.json:

{                                               
"compilerOptions": {                          
"target": "es5",                            
"lib": [                                    
"dom",                                    
"dom.iterable",                           
"esnext"                                  
],                                          
"allowJs": true,                            
"skipLibCheck": true,                       
"strict": false,                            
"forceConsistentCasingInFileNames": true,   
"noEmit": true,                             
"esModuleInterop": true,                    
"module": "esnext",                         
"moduleResolution": "node",                 
"resolveJsonModule": true,                  
"isolatedModules": true,                    
"jsx": "preserve"                           
},                                            
"include": [                                  
"next-env.d.ts",                            
"**/*.ts",                                  
"**/*.tsx", "mptools/Helpers/range.ts"      
],                                            
"exclude": [                                  
"node_modules"                              
]                                             
}                                               

好吧,我解决了这个问题。删除node_modules和package.json并再次执行npm I并没有帮助,但删除整个文件夹并再次从git中提取解决了问题。不知道问题是什么,但是。。。啊。

在用以下行更新next-env.d.ts后,我能够构建我的项目:

/// <reference types="next" />
/// <reference types="next/types/global" />

线条必须与上面显示的完全相同。

我以这个项目为例:https://github.com/jpedroschmitz/typescript-nextjs-starter

最新更新