如何解决“找不到模块:错误:无法解析'../../clientAndAPi/follow”“

时间:2019-04-05 20:03:06

标签: javascript heroku webpack

我正在尝试使用git push heroku master将Java应用程序推送到heroku。从我的webpack.config.js创建bundle.js文件时,出现了此错误->

  

“未找到模块:错误:无法解析'./tmp/build_3ee67cfe22a500174d8ca2c8820a8a21/sneakysneaksGUI/src/components/Landing中的'../../clientAndAPi/follow'”“

输出应为已编译的bundle.js,且无错误 我正在尝试使用git push heroku master将Java应用程序推送到heroku。当需要从webpack.config.js创建bundle.js文件时,出现此错误->

  

“未找到模块:错误:无法解析'./tmp/build_3ee67cfe22a500174d8ca2c8820a8a21/sneakysneaksGUI/src/components/Landing中的'../../ clientAndAPi / follow'”

我尝试更改导入文件(import follow from --> const follow = require..)的方式,这导致了同样的错误。 我还尝试将follow.js文件中的module.exports更改为导出默认值

//imports in Landing.jsx

const follow = require('../../clientAndAPi/follow');
//import follow from '../../clientAndAPi/follow'; // function to hop multiple links by "rel"
//both ways produce problem
//follow.js
module.exports = function follow(api, rootPath, relArray) {
    const root = api({
        method: 'GET',
        path: rootPath
    });

    return relArray.reduce(function(root, arrayItem) {
        const rel = typeof arrayItem === 'string' ? arrayItem : arrayItem.rel;
        return traverseNext(root, rel, arrayItem);
    }, root);

    function traverseNext (root, rel, arrayItem) {
        return root.then(function (response) {
            if (hasEmbeddedRel(response.entity, rel)) {
                return response.entity._embedded[rel];
            }

            if(!response.entity._links) {
                return [];
            }

            if (typeof arrayItem === 'string') {
                return api({
                    method: 'GET',
                    path: response.entity._links[rel].href
                });
            } else {
                return api({
                    method: 'GET',
                    path: response.entity._links[rel].href,
                    params: arrayItem.params
                });
            }
        });
    }

    function hasEmbeddedRel (entity, rel) {
        return entity._embedded && entity._embedded.hasOwnProperty(rel);
    }
};
//webpack.config.js
var path = require('path');

module.exports = {
  //TODO -- Change to the real location of app.js 
  entry: './sneakysneaksGUI/src/index.js',
  devtool: 'sourcemaps',
  cache: true,
  mode: 'development',
  output: {
    path: __dirname,
    filename: './src/main/resources/static/built/bundle.js'
  },
  module: {
    rules: [
      {
        test: path.join(__dirname, '.'),
        exclude: /(node_modules)/,
        use: [{
          loader: 'babel-loader',
          options: {
            presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-flow"]
          }
        }]
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ['babel-loader']
      }
    ]
  },
  resolve: {
    extensions: ['*', '.js', '.jsx']
  }
};

当前提供了一个错误。 输出应该是没有错误的编译后的bundle.js

0 个答案:

没有答案