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?
Found that I apparently need this file:
.mocharc.json
{
"node-option": [
"experimental-specifier-resolution=node"
]
}