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

106
Visualizações
Cannot get basic index.js to work in simple mocha test project

I have a simple project laid out like:

project
│   package.json    
│
└───productA
│   │
│   └───test
│       │   spec1.js
│   
└───common
    index.js
    │
    └───sharedFunction1
        │   auth.js
        │   index.js
      

In spec1.js, I can successfully import a function from auth.js like this:

import { some_function } from "../../common/sharedFunction1/auth.js"

However, I thought that I should be able to use index.js files so that I can import like this:

import { some_function } from "../../common"

The function I am trying to import is something like (just a simple example):

export function get_file_listing (folder) {
    var files = fs.readdirSync(folder);
    return files
}

and my index.js under sharedFunction1 looks like:

export * from './auth';

and my index.js under common looks like:

export * from "./sharedFunction1";

VSCode auto import in the spec file seems to think the import should be:

import { some_function } from "../../common";

But when I run my test with that I get:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import ... is not supported resolving ES modules imported from ...

My package.json has:

  "type": "module",

I have read a hundred different pages trying to understand what I am doing wrong, but am stuck. Can anyone tell me what I am doing wrong or if this should even work?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Found that I apparently need this file:

.mocharc.json

{
    "node-option": [
        "experimental-specifier-resolution=node"
    ]
}
about 4 years ago · Juan Pablo Isaza Relatório
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