【问题标题】:Differences between requiring local module versus node_modules module需要本地模块与 node_modules 模块之间的差异
【发布时间】:2023-04-02 10:56:01
【问题描述】:

A 在node_modules 文件夹内的私有库中具有以下转译代码。

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _graphql = require('graphql');

var FileTypeEnum = new _graphql.GraphQLEnumType({
  name: 'FileType',
  description: 'The types of report files.',
  values: {
    CSV: {
      value: 'CSV',
      description: 'Comma-separated values.'
    },
    XLS: {
      value: 'XLS',
      description: 'Microsoft Excel.'
    }
  }
});

exports.default = FileTypeEnum;

我的问题是当我需要它时,它带有一个具有正确属性的对象,但不是 GraphQLEnumType 的实例。另一方面,如果在我的项目中复制这个模块,就像一个本地模块一样,它可以完美地工作。

import FileTypeA from 'my_lib/graphql/report/types/FileTypeEnum';
import FileTypeB from '../types/FileTypeEnum';

console.log(FileTypeA instanceof GraphQLEnumType); # false
console.log(FileTypeB instanceof GraphQLEnumType); # true

如果不是 GraphQLEnumType,我将无法使用此类。有什么建议吗?

【问题讨论】:

  • 您在node_modules 中的“私有库”是否依赖于与您的项目不同的graphql 版本?

标签: node.js graphql


【解决方案1】:

也许您的库与您的应用程序的 graphql 版本不同。

【讨论】:

    猜你喜欢
    • 2016-06-08
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 2015-12-20
    • 1970-01-01
    相关资源
    最近更新 更多