Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Can't resolve specificy import on my package

I created a package with CRA, Typescript and Storybook.

There is some configs from my package.json:

"name": "@my-name/my-package",
  "version": "0.0.7",
  "main": "./dist/index.js",
  "exports": {
    ".": "./dist/index.js",
    "./interfaces": "./dist/interfaces",
    "./contexts": "./dist/contexts"
  },
  "types": "./dist/index.d.ts",
  "typesVersions": {
    "*": {
      "interfaces": [
        "./dist/interfaces/index.d.ts"
      ],
      "contexts": [
        "./dist/contexts/index.d.ts"
      ]
    }
  },

When I import like this, it's works fines:

import { Button } from '@my-name/my-package';
import { ButtonInterface } from '@my-name/my-package/interfaces';

But when I try to import like this:

import { ButtonContext } from '@my-name/my-package/contexts';

I get this error:

Module not found: Can't resolve '@my-name/my-package/contexts' in '/home/my-pc/Documents/my-project/src/pages/Home'

I really don't know why I can import interfaces, but can't import contexts.

I tried import the ButtonContext from my main entry point, and it's worked. But then I try to import it from "./contexts" entry, I get the module not found error.

Here is my tsconfig.json that I use to create the dist folder:

{
  "compilerOptions": {
    "declaration": true,
    "strictNullChecks": true,
    "outDir": "dist",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "lib": ["es2015", "dom"],
    "rootDir": "src",
    "jsx": "react-jsx",
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "allowJs": true
  },
  "include": ["src"],
  "exclude": [
    "node_modules",
    "dist",
    "./src/stories",
    "./src/**/*.stories.**",
    "./src/mock",
    "./src/**/*.test.*",
    "./src/setupTests.ts"
  ]
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda