无法解析“ ./../src/entity”Webpack、TypeORM、Babel、Node

时间:2019-08-08 17:14:27

标签: javascript node.js webpack graphql typeorm

我正在尝试使用typeorm,graphql-yoga在后端项目中使用webpack。

我的webpack.config.js是以下内容。

const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  mode: "development",
  target: 'node',
  externals: [nodeExternals()],
  devtool: "source-map",
  entry: './src',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      }
    ]
  }
}

,当我运行脚本时,收到以下警告。

WARNING in ./src/utils/DBQuery.js
Module not found: Error: Can't resolve './../src/entity' in '/home/user/Documents/APPS/project/src/utils'
 @ ./src/utils/DBQuery.js
 @ ./src/entity/Country/Country.QM.js
 @ ./src/Query.js
 @ ./src/index.js

如果我检查文件,则其内部具有以下功能。

const getAvailableActions = (repository) => {
  try {
    // Obtiene las queries y mutations disponibles para el repositorio
    const REPO = require(`./../src/entity/${repository}/${repository}.schema`)
    const queriesMutations = `${REPO.default.Queries}${REPO.default.Mutations}`
    const regex = /\w+(?=: \[|\()/g;
    let m;
    const matches = []
    while ((m = regex.exec(queriesMutations)) !== null) {
      if (m.index === regex.lastIndex) {
        regex.lastIndex++;
      }
      m.forEach((match, groupIndex) => {
        matches.push(match)
      });
    }
    return matches
  } catch (error) {
    throw new Error(error)
  }
}

该函数的目的是根据传递给函数的内容以编程方式加载模式。

关于如何解决此问题的任何想法或建议? 谢谢。

0 个答案:

没有答案