简体   繁体   English

反应:找不到模块:无法解析

[英]React: Module not found: Can't resolve

I'm developing a simple React App with Prisma, Apollo Client, GraphQL-yoga. 我正在使用Prisma,Apollo Client,GraphQL-yoga开发一个简单的React App。 While following this tutorial about react-apollo-form I encountered this problem. 在遵循有关react-apollo-form的本教程时,我遇到了此问题。

./src/components/CreateEntry.js
Module not found: Can't resolve '../forms/ApplicationForm' in 'C:\Users\massi\Desktop\sandbox\erbar10\erbar10\src\components'

My tree 我的树

在此处输入图片说明

CreateEntry.js CreateEntry.js

import React, { Component } from "react";
import { withApollo } from "react-apollo";
import gql from "graphql-tag";
import { ApplicationForm } from "../forms/ApplicationForm";

const CREATE_DRAFT = gql`
  mutation createDraft($name: String!) {
    createDraft(name: $name, scientificName: $scientificName, file: $file) {
      id
      name
      scientificName
    }
  }
`;

class CreateEntry extends Component {
  render() {
    return (
      <ApplicationForm
        title="Entry Form"
        liveValidate={true}
        config={{
          mutation: {
            name: "createDraft",
            document: CREATE_DRAFT
          }
        }}
        data={{}}
        ui={{}}
      />
    );
  }
}

export default withApollo(CreateEntry);

ApplicationForm.ts 申请表格

import * as React from "react";
import { configure } from "react-apollo-form";
import client from "../index";

const jsonSchema = require("./apollo-form-json-schema.json");

const ApplicationForm = configure<ApolloFormMutationNames>({
  client: client as any,
  jsonSchema
});

export default ApplicationForm;

I checked and checked my imports but I cannot find a solution. 我检查并检查了我的进口货,但找不到解决方案。 Is the problem relative to the .ts file? 问题是否与.ts文件有关? I'm sure I'm losing myself in a glass of water. 我确定我会迷失在一杯水中。


Update: There is also another problem: on ApplicationForm.ts ApolloFormMutationNames is highlighted with "Cannot find name ApolloFormMutationNames". 更新:还有另一个问题:在ApplicationForm.ts上,ApolloFormMutationNames突出显示为“找不到名称ApolloFormMutationNames”。

mutations.d.ts 突变

/* this file is generated, do not edit and keep it in tsconfig.rootDir scope! */

declare type ApolloFormMutationNames =
  | "createDraft"
  | "deleteEntry"
  | "publish"
  | "setToBeReviewed";

只需删除导入中的ApplicationForm括号即可。

import ApplicationForm from "../forms/ApplicationForm";

Did you try removing the brackets from the ApplicationForm import? 您是否尝试从ApplicationForm导入中删除括号? Looking at some other examples they didn't add brackets. 查看其他示例,他们没有添加括号。 See this GitHub as an example. 请参阅 GitHub作为示例。 The linked file imports a TypeScript file with a directory pattern similar to yours. 链接文件将导入TypeScript文件,该文件的目录模式与您的相似。

import ApplicationForm from "../forms/ApplicationForm";

As vitomadio said before, you don't need to use curly braces {} because you have default export in your file. 正如vitomadio之前所说,您不需要使用花括号{}因为文件中具有默认导出功能。

import ApplicationForm from "../forms/ApplicationForm"; should fix your problem. 应该解决您的问题。

it will explain when you need to use curly braces and when you need to omit them 它将说明何时需要使用花括号以及何时需要省略花括号

When should I use curly braces for ES6 import? 什么时候应该将花括号用于ES6导入?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM