Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:无法使用GraphQLSchema";[object GraphQLSchema]”;来自另一个模块或领域_Javascript_Node.js_Ecmascript 6_Graphql_Graphql Js - Fatal编程技术网

Javascript 错误:无法使用GraphQLSchema";[object GraphQLSchema]”;来自另一个模块或领域

Javascript 错误:无法使用GraphQLSchema";[object GraphQLSchema]”;来自另一个模块或领域,javascript,node.js,ecmascript-6,graphql,graphql-js,Javascript,Node.js,Ecmascript 6,Graphql,Graphql Js,给定以下代码: import { graphql } from 'graphql' import graphqlTools from 'graphql-tools' const { makeExecutableSchema } = graphqlTools const typeDefs = ` type Query { as: [A] } type A { x: Int, y: Int } ` const schema = makeExecutableSchema ({

给定以下代码:

import { graphql } from 'graphql'
import graphqlTools from 'graphql-tools'

const { makeExecutableSchema } = graphqlTools

const typeDefs = `
type Query {
   as: [A]
}

type A {
   x: Int,
   y: Int
}
`
const schema = makeExecutableSchema ({ typeDefs })

graphql(schema, '{ as { x, y } }').then(console.log)
我得到这个错误:

错误:无法从其他对象使用GraphQLSchema“[object GraphQLSchema]” 模块或领域

确保中只有一个“graphql”实例 节点\模块目录。如果使用不同版本的“graphql” 其他依赖模块的依赖关系,使用“解决方案”确保 只安装了一个版本


发生了什么?

发生这种情况是因为
graphql工具
模块从其CommonJS模块导入
graphql
,而我的代码从ES模块导入。也就是说,我自己模块中的每个对象都来自ES模块,而
图形工具
不是

解决方案 从
graphql
导入CommonJS模块与从
graphql
graphql工具
导入任何东西一样简单,两个对象都可以相互对话:

import graphql_ from 'graphql/index.js'
import graphqlTools from 'graphql-tools'

const { graphql } = graphql_
const { makeExecutableSchema } = graphqlTools

const typeDefs = `
type Query {
   as: [A]
}

type A {
   x: Int,
   y: Int
}
`
const schema = makeExecutableSchema ({ typeDefs })

graphql(schema, '{ as { x, y } }').then(console.log)

当您安装的
graphql
模块的版本与
graphql工具安装和使用的版本不同时,也可能出现这种情况

我发现您可以通过以下任一方法来纠正此问题:

  • 在项目的
    package.json
    文件中更改
    graphql
    的版本,以精确匹配
    graphql工具在其
    package.json
    文件中所依赖的内容

  • 作为依赖项删除
    graphql
    ,只需安装
    graphql工具
    。然后,您将自动收到
    graphql工具
    安装的任何
    graphql
    模块版本(只要您不依赖于安装另一个冲突版本的任何其他软件包)


  • 在其他情况下,您可能有正确的版本,但可能会安装多次。您可以使用
    npm ls graphql
    查看所有安装的版本。尝试运行
    npm duplicate
    删除重复安装。

    我的问题是
    .js
    .mjs
    由于网页包配置错误,graphql文件已解决

    根本原因:

    graphql compose
    中的
    TypeMapper.mjs
    文件中,导入语句没有文件扩展名,这是webpack bundle上的一个故障。为了解决这个问题,我需要在网页配置中添加
    fullysspecified:false

    {
    测试:/\.m?js/,
    包括:/node\u模块/,
    键入:“javascript/auto”,
    决心:{
    完全指定:false
    }
    }
    
    我还修改了resolve语句,比如

    解析:{
    扩展:[“.ts”、“.js”、“.mjs”]//这就是实际问题所在
    }
    
    由于
    fullysspecified
    config已设置为
    false
    ,webpack尝试解析文件,但没有扩展名,顺序为
    resolve.extensions
    config。由于该配置中的顺序错误,
    graphql
    文件和
    .js
    ext正在解析,尽管所有其他文件都在使用
    .mjs
    one

    解决方案:

    只需重新排序
    resolve.extensions
    config as

    解析:{
    扩展名:[“.ts”、“.mjs”、“.js”]
    }
    
    当我的.npmrc没有正确的输入,如用户名和密码时,我得到了这个准确的错误。我们正在使用jFrog使软件包安装正常化。npmrc应位于根目录下,并有适当的条目。 例如:.npmrc文件,它可以工作

    @<company-name>:registry=<registry-url>
    //<artifactory-name>:_password=${PASSWORD}
    //<artifactory-name>:username=${JFROG_USERNAME}
    //<artifactory-name>:email=${YOUR_EMAIL}
    //<artifactory-name>:always-auth=true
    
    @:注册表=
    //:_password=${password}
    //:username=${JFROG\u username}
    //:email=${YOUR_email}
    //:always auth=true
    
    这对我很有效,
    ls
    命令为我提供了上下文,但
    重复数据消除
    将其清理干净。