要求本地模块与node_modules模块之间的差异

A在私有库中有一个在node_modules文件夹内的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的一个实例。 另一方面,如果在我的项目中创build一个本地模块的副本,就像本地模块一样,它可以很好地工作。

 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,我不能使用这个类。 有什么build议么?

也许你的库有一个不同于你的应用程序的graphql版本。