简体   繁体   English

webpack错误-找不到模块:错误:无法解析“ ImageFile”

[英]webpack error - Module not found: Error: Can't resolve 'ImageFile'

I am using react-native-simple-login component in my reactjs native app. 我在我的reactjs本机应用程序中使用react-native-simple-login组件。

npm install --save react-native-simple-login

在此处输入图片说明

ERROR in ./~/react-native-simple-login/Login/index.js
Module not found: Error: Can't resolve './Images/email_icon.png' in '/home/xxx/projects/react-native-web-boilerplate/node_modules/react-native-simple-login/Login'
 @ ./~/react-native-simple-login/Login/index.js 107:28-62
 @ ./~/react-native-simple-login/index.js
 @ ./src/navigation.js
 @ ./index.web.js
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server webpack-dev-server/client?http://localhost:3000 webpack/hot/only-dev-server react-hot-loader/patch ./index.web.js

ERROR in ./~/react-native-simple-login/Login/index.js
Module not found: Error: Can't resolve './Images/password_icon.png' in '/home/xxx/projects/react-native-web-boilerplate/node_modules/react-native-simple-login/Login'
 @ ./~/react-native-simple-login/Login/index.js 108:18-55
 @ ./~/react-native-simple-login/index.js
 @ ./src/navigation.js
 @ ./index.web.js
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server webpack-dev-server/client?http://localhost:3000 webpack/hot/only-dev-server react-hot-loader/patch ./index.web.js

email_icon.png , password_icon.png belong to react-native-simple-login . email_icon.pngpassword_icon.png属于react-native-simple-login Why webpack is complaining? 为什么webpack在抱怨?

webpack.config.js webpack.config.js

const webpack = require('webpack');

const path = require('path');

module.exports = {
  devServer: {
    contentBase: path.join(__dirname, 'build'),
    // enable HMR
    hot: true,
    // embed the webpack-dev-server runtime into the bundle
    inline: true,
    // serve index.html in place of 404 responses to allow HTML5 history
    historyApiFallback: true,
    port: 3000
  },
  devtool: 'source-map',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    'react-hot-loader/patch',
    path.join(__dirname, '../index.web.js')
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        include: [
          path.resolve(__dirname, '..', 'index.web.js'),
          path.resolve(__dirname, '..', 'src'),
          path.resolve(__dirname, '..', 'src/components'),
          path.resolve(__dirname, '..', 'src/images'),
          path.resolve(__dirname, '../node_modules/react-native-vector-icons'),
          path.resolve(__dirname, '../node_modules/react-native-tab-view'),
          path.resolve(__dirname, '../node_modules/react-native-simple-login')
        ],
        loader: 'babel-loader',
        query: {
          presets: ["react-native","es2015", "stage-0", "react"]
        }
      },
      {
        test: /\.(gif|jpe?g|png|svg)$/,
        loader: 'url-loader',
        query: { name: '[name].[hash:16].[ext]' }
      },
    ]
  },
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'bundle.js'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('development')
      },
    })
  ],
  resolve: {
    modules: [
      path.join(__dirname, '..', 'node_modules')
    ],
    alias: {
      'react-native': 'react-native-web',
      'react-navigation': 'react-navigation/lib/react-navigation.js',
        'react-native-simple-login': 'react-native-simple-login'
    }
  }
};

Try running webpack --display-error-details . 尝试运行webpack --display-error-details The error may not be related to file resolution. 该错误可能与文件解析无关。

more detial here: https://github.com/webpack/webpack/issues/981 更多细节在这里: https : //github.com/webpack/webpack/issues/981

Maybe it's a directory problem? 也许是目录问题? I don't know your project folder setup but i'm saying try to change the code to ../../Images/email_icon.png , the same goes for the second error. 我不知道您的项目文件夹设置,但我是说尝试将代码更改为../../Images/email_icon.png ,第二个错误也是如此。

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

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