简体   繁体   English

当我尝试使用 Parcel 构建在开发模式下运行良好的 React 应用程序的生产版本时,我得到“找不到模块 'sass'”

[英]When I try to use Parcel to build a production version of a React app that works fine in development mode, I get “Cannot find module 'sass'”

I've built a simple React/Redux app and am using Parcel for the bundler.我已经构建了一个简单的 React/Redux 应用程序,并且正在使用 Parcel 作为捆绑器。 It works fine in development mode, that is, using the script它在开发模式下工作正常,即使用脚本

"dev": "parcel ./src/index.html",

but when I tried to do但是当我试图做

"build": "parcel build ./src/index.html",

I got the following error我收到以下错误

/Users/abc/Documents/Projects/sandbox/smart/src/styles/main.scss: Cannot find module 'sass' from '/Users/abc/Documents/Projects/sandbox/smart/src/styles'
    at /Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:97:35
    at processDirs (/Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:244:39)
    at isdir (/Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:251:32)
    at /Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:23:69
    at FSReqWrap.oncomplete (fs.js:152:21)

This is the first time I've tried to build an app using Parcel and I'm lost.这是我第一次尝试使用 Parcel 构建应用程序,但我迷路了。 I'm using node-sass to import my sass files directly -- perhaps this has something to do with that.我正在使用node-sass直接导入我的 sass 文件——也许这与此有关。

The referenced file ( main.scss ) is referenced in App.js like this引用的文件( main.scss )在App.js中像这样引用

import "../../styles/main.scss";

and is the first sass file to be included (App is loaded into the DOM like this in index.js :并且是第一个要包含的 sass 文件(应用程序在index.js中像这样加载到 DOM 中:

const store = configureStore()
ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById("root")
)

This is running under Node 11.15.这是在节点 11.15 下运行的。 My package.json follows -- any hints or help much appreciated!我的package.json如下 - 任何提示或帮助非常感谢!

{
  "name": "friender",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "jest": {
    "setupFiles": ["jest-localstorage-mock"]
  },
  "scripts": {
    "dev": "parcel ./src/index.html",
    "build": "parcel build ./src/index.html",
    "lint": "eslint \"src/**/*.{js,jsx}\" --quiet",
    "test": "jest"
  },
  "prettier": {
    "semi": false
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "@babel/cli": "^7.6.0",
    "@babel/core": "^7.6.0",
    "@babel/plugin-transform-runtime": "^7.5.5",
    "@babel/preset-env": "^7.6.0",
    "@types/jest": "^24.0.18",
    "babel-eslint": "^10.0.3",
    "babel-preset-react": "^7.0.0-beta.3",
    "eslint": "^6.2.2",
    "eslint-config-prettier": "^6.1.0",
    "jest": "^24.9.0",
    "jest-localstorage-mock": "^2.4.0",
    "parcel-bundler": "^1.12.3",
    "prettier": "^1.18.2"
  },
  "dependencies": {
    "@emotion/babel-preset-css-prop": "^10.0.14",
    "@emotion/core": "^10.0.16",
    "@emotion/styled": "^10.0.15",
    "@fortawesome/fontawesome-svg-core": "^1.2.0-7",
    "@fortawesome/free-solid-svg-icons": "^5.11.1",
    "@fortawesome/react-fontawesome": "^0.1.4",
    "axios": "^0.19.0",
    "bulma": "^0.7.5",
    "eslint-plugin-jest": "^22.17.0",
    "eslint-plugin-react": "^7.14.3",
    "immer": "^4.0.0",
    "node-sass": "^4.12.0",
    "prop-types": "^15.7.2",
    "react": "16.x",
    "react-detect-offline": "^2.4.0",
    "react-dom": "^16.9.0",
    "react-fontawesome": "^1.6.1",
    "react-modal": "^3.10.1",
    "react-redux": "^7.1.1",
    "redux": "^4.0.4",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0"
  }
}

Try instead per the documentation for SCSS and error Cannot find module 'sass' use module sass instead of node-sass :尝试按照SCSS 的文档和错误Cannot find module 'sass'使用模块sass而不是node-sass

npm install -D sass

The documentation mentions being able to use node-sass , but there are several active issues with node-sass .文档提到能够使用node-sass ,但是 node- node-sass有几个活跃的问题。 Module sass may help resolve the error and allow you use SCSS in your application.模块sass可能有助于解决错误并允许您在应用程序中使用 SCSS。

Hopefully that helps!希望这会有所帮助!

暂无
暂无

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

相关问题 Angular / JS Express应用程序在生产模式下处于无限路由循环中,在开发模式下运行良好 - Angular/JS Express app in infinite routing loop in production mode, works fine in development mode 生产构建后如何在反应应用程序中使用节点模块? - How can I use node module in react app after production build? React 应用程序无法通过其请求在生产中访问我的快速应用程序,但在开发中运行良好 - React app can't reach my express app in production with its requests but works fine in development React Chat 应用程序在生产环境中运行良好,但在开发环境中无法正常运行(聊天应用程序)| React(使用 Materia-ui),Socket.io,Express - React Chat app works fine in Production but not in Development (Chat App) | React (with Materia-ui), Socket.io, Express `react-hover` npm软件包不在生产版本中,但在开发中运行良好 - `react-hover` npm package not in production build but working fine in development 当我尝试创建 React 应用程序时,出现“未提供模板,这可能是因为您使用的是过时版本的 create-react-app”错误 - when i try to create react app ,i get " template was not provided ,This is likely because you're using an outdated version of create-react-app " Error 每当我尝试通过 Heroku 运行我的服务器时,我都会收到“错误:找不到模块 'dotenv'” - Whenever I try to run my server via Heroku I get "Error: Cannot find module 'dotenv'" 尝试将获取请求从控制器模块导入到主应用程序时出现错误。 (类型错误:无法读取未定义的正确“获取”) - I get an error when I try to import a get request from a controller module to my main app. (Type-error : Cannot read proper 'get' of undefined) Babel / Webpack:找不到“ yaml-loader”(开发中的产品,而非生产中的产品) - Babel / Webpack: Cannot find “yaml-loader” (works in development, not production) 在生产中出现此错误,但在开发中工作正常 - StripeInvalidRequestError: The `line_items` parameter is required in payment mode - Getting this error in production but works fine in development - StripeInvalidRequestError: The `line_items` parameter is required in payment mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM