javascript - 模块无法在 React App 中加载。获取 "ERROR in ./~/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js"

标签 javascript reactjs webpack sass

尝试将我的项目从 css 转换为 sass 时出现错误。我想我已经加载了正确的模块,但似乎这些模块没有正确加载。 这是我得到的错误。

ERROR in ./~/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js
Module build failed: Error: ENOENT: no such file or directory, open   '/Volumes/server2/Desktop/JavaScript/invoiced-ui/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js'
@ ./~/react-router/es/withRouter.js 6:0-51
@ ./~/react-router/es/index.js
@ ./app/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-  server ./app

ERROR in ./~/css-loader?{"modules":true,"importLoaders":1,"localIdentName":"   [path]_[name]_[local]_[hash:base64:5]"}!./~/sass-loader/lib/loader.js?{"includePaths":["./vendor","./app"]}!./app/components/Collection.sass
Module build failed: Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (59)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v3.13.1
at module.exports (/Volumes/server2/Desktop/JavaScript/invoiced-ui/node_modules/node-sass/lib/binding.js:13:13)
at Object.<anonymous> (/Volumes/server2/Desktop/JavaScript/invoiced-ui/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.sassLoader (/Volumes/server2/Desktop/JavaScript/invoiced-ui/node_modules/sass-loader/lib/loader.js:46:72)
 @ ./app/components/Collection.sass 4:14-148 13:2-17:4 14:20-154
 @ ./app/components/Collection.js
 @ ./app/components/index.js
 @ ./app/routes.js
 @ ./app/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-  server ./app

我正在使用 yarn 来加载依赖项,想知道是否有一些我应该用 Webpack 完成的事情? 下面是我的 webpack,我想知道这里是否缺少什么?

const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
app: './app',
 },
 output: {
path: __dirname,
publicPath: '/',
filename: '[name].js',
chunkFilename: '[id].js',
},
devServer: {
hot: true,
inline: true,
historyApiFallback: true,
},
resolve: {
modules: ['node_modules', 'lib', 'app', 'vendor'],
},
module: {
rules: [
  {
    test: /\.css$/,
    use: [
      'style-loader',
      'css-loader',
    ],
  }, {
    test: /\.(jpe?g|png|gif|svg)$/i,
    use: [
      {
        loader: 'file-loader',
        options: {
          hash: 'sha512',
          digest: 'hex',
          name: '[hash].[ext]',
        },
      }, {
        loader: 'image-webpack-loader',
        options: {
          bypassOnDebug: true,
        },
      },
    ],
  }, {
    test: /\.(scss|sass)$/,
    use: [{
      loader: 'style-loader',
    }, {
      loader: 'css-loader',
      options: {
        modules: true,
        importLoaders: 1,
        localIdentName: '[path]_[name]_[local]_[hash:base64:5]',
      },
    }, {
      loader: 'sass-loader',
      options: {
        includePaths: ['./vendor', './app'],
      },
    }],
  },
  {
    test: /\.(js|jsx)$/,
    exclude: /(node_modules|bower_components)/,
    loader: 'babel-loader',
    query: {
      presets: ['es2015', 'stage-0', 'react'],
      plugins: ['transform-runtime', 'transform-decorators-legacy'],
    },
  },
],
},
 plugins: [
],
};

最佳答案

检查合适的样式、css 和 sass 加载器以及它们的使用顺序:style -> css -> sass

关于javascript - 模块无法在 React App 中加载。获取 "ERROR in ./~/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52937804/

相关文章:

javascript - jQuery 或 Javascript 自动格式化电话掩码

javascript - 如何使用 ng-repeat 对二维 json 对象应用过滤器?

reactjs - 如何在 React Native 中创建可拖动组件?

angular - 执行启动脚本失败

JavaScript 正则表达式用 %21 替换 %2F

javascript - for 循环内的函数 - 如何正确执行?

javascript - 导入语法 React Redux

reactjs - 如何通过Material ui select使下拉菜单下拉

javascript - webpack-dev-server 没有在本地创建 dist 文件夹

vue.js - Vue-cli 生产构建不显示静态图像