我创建了一个空白的 React 项目,使用命令:npx create-react-appon npm v7.0.7 和 Node v15.0.1
安装:
然后我尝试将空白的 .scss 文件导入 App 组件:
应用程序.js
import './App.scss'
function App() {
return (
<div className="App">
App
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
抛出错误:
Failed to compile.
./src/App.scss (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-6-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-6-3!./node_modules/s
ass-loader/dist/cjs.js??ref--5-oneOf-6-4!./src/App.scss)
Error: Node Sass version 5.0.0 is incompatible with ^4.0.0.
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "react-17-node-sass-5",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"node-sass": "^5.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4" …Run Code Online (Sandbox Code Playgroud) 我尝试安装 sass-loader 来编译 scss,但它显示了一个版本兼容性错误。我降级了版本并做了很多事情,但仍然显示相同的问题。
React 版本 - 17.0.2 节点版本 - 16.2.0 npm 版本 - 7.13.0
包.json
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"antd": "^4.16.2",
"node-sass": "^4.14.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.4",
"react-scripts": "4.0.3",
"redux-saga": "^1.1.3",
"web-vitals": "^1.0.1"
},
Run Code Online (Sandbox Code Playgroud)