简体   繁体   English

create-react-app 上的 node-sass 问题

[英]Problem with node-sass on create-react-app

Before I post this question, I have tried all of the solution offered down below: ERROR in Cannot find module 'node-sass'在我发布这个问题之前,我已经尝试了下面提供的所有解决方案: 找不到模块'node-sass'中的错误

I use create-react-app to create project1 on Windows 10.我使用 create-react-app 在 Windows 10 上创建 project1。

My node version: node -v -> v12.16.3我的节点版本:node -v -> v12.16.3

Install node-sass: npm install node-sass@latest安装node-sass:npm install node-sass@latest

App.js:应用程序.js:

import React from 'react';

import "assets/scss/style.scss";


function App() {
  return (
     <div>Hi World</div>
  );
}

export default App;

npm start npm启动

Error on the browser: ./src/App.js Module not found: Can't resolve 'assets/scss/style.scss' in 'F:\project1\src'浏览器上的错误:./src/App.js 未找到模块:无法解析 'F:\project1\src' 中的 'assets/scss/style.scss'

I'm just wondering why isn't there a simpler and guarentee-to-work way to get this node-sass installed and run.我只是想知道为什么没有一种更简单和保证工作的方式来安装和运行这个 node-sass。 After I searched up for solution on google, it turns out that a lot of people (not only me) are having the same problem.在我在谷歌上搜索解决方案后,发现很多人(不仅是我)都遇到了同样的问题。

https://github.com/sass/node-sass https://github.com/sass/node-sass

You can install node-sass@4.12 according to your node version.你可以根据你的node版本安装node-sass@4.12。

You just need to flow three steps:您只需要流程三个步骤:

  1. npm install node-sass npm 安装 node-sass
  2. change file extension (.css to.scss )更改文件扩展名(.css to.scss)
  3. change any import to.scss将任何导入更改为 .scss
  4. provide proper path for style.scss file( May I know your style.scss path? )为 style.scss 文件提供正确的路径(我可以知道你的 style.scss 路径吗?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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