create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

export * from, and module has no exports

Open Vincent-Alexandrine opened this issue 3 years ago • 3 comments

Hey 👋

I'm having some kind of issue while importing/exporting modules when using index files.

I'm having my repo this way:

  • /src
    • /services
      • index.ts
      • /serviceA
        • index.ts
        • serviceA.ts
      • /serviceB
        • index.ts
        • serviceB.ts

My index.ts files in each service do

export * from "./serviceX";

And the index file in the folder /services does:

export * from "./serviceA";
export * from "./serviceB";

In another file i do:

import { serviceA } from "services";

At first, it works and it imports the module finely. But I've noticed that when I switch of git branch, and then come back to the previous branch: those kind of import don't work anymore (when it was working originally).

I've been working on a couple of branches, then after some merges, when checking out the main branch, all the previous work is bugged due to this issue.

However, for now I've been able to find another way to do those export, which is this way:

export { serviceA } from "./serviceA";

Then the imports work fine, but I still find it more comfortable to use * instead of naming each module.

the project use:

  • react-scripts: 5.0.1
  • yarn: 3.2.1

Thanks everyone, have a nice day 🖖

Vincent-Alexandrine avatar Aug 18 '22 09:08 Vincent-Alexandrine

doesn't seem like create-react-app issue

just add these properties to tsconfig.json { "compilerOptions": { "baseUrl": "./src", }, "include":["src"] }

or import like "./services" instead of "services"

sunil-sharma-999 avatar Aug 19 '22 12:08 sunil-sharma-999

Hey @sunil-sharma-999 👋 I've been using those properties for a couple of days to see how it goes, but I still have the problem with typescript from time to time. I suspect some kind of problem with some sort of caching of the dev server.

Vincent-Alexandrine avatar Aug 23 '22 12:08 Vincent-Alexandrine

@Vincent-Alexandrine Probably caching issue i guess. I don't use typescript much but whenever i use it the typescript linting lags a bit.

sunil-sharma-999 avatar Aug 23 '22 12:08 sunil-sharma-999

Hey :wave:

Thanks you, the solution seems to write ./src instead of src for both baseUrl and include.

Vincent-Alexandrine avatar Oct 20 '22 09:10 Vincent-Alexandrine

I hit the same problem in my project. But using ./src in baseUrl and include did not help.

UPDATE: It actually worked. weird.

vijayth2-cerebras avatar Jun 09 '24 03:06 vijayth2-cerebras