Utilizing cucumberjs
to test various components of my project has been successful. However, I encountered an issue in one step where I utilize a zod
schema that is defined within a private npm module:
// within the private npm package:
// constant.js
import { z } from 'zod';
export const ROLES = z.enum([
'ROLE_USER',
'ROLE_EMPLOYEE',
'ROLE_MANAGER',
]);
This npm package is installed at a higher level and I am facing the following error:
/Users/../node_modules/@privateModule/schemas/lib/constants.js:1
import { z } from 'zod';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I find it perplexing why all other modules function correctly except this one.
Here is the tsconfig.json
for the testing component:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"sourceMap": true,
"baseUrl": ".",
"paths": {
"core/*": ["../core/src/*"],
}
}
}
And here is the configuration from the parent folder:
{
"extends": "@tsconfig/node18/tsconfig.json"
}
It seems like every time I try to import something from this private module, a similar error occurs.
As requested, here is the package.json
file of the private module (I have excluded dependencies, name, author, and scripts):
{
"type": "module",
"main": "./dist/index.js",
"exports": {
"./functions": "./dist/functions/index.js",
"./schemas": "./dist/schemas/index.js",
".": "./dist/index.js"
},
"typesVersions": {
"*": {
"functions": [
"dist/functions/index.d.ts"
],
"schemas": [
"dist/schemas/index.d.ts"
],
"*": [
"dist/index.d.ts"
]
}
},
}
Regarding the package.json
of the component running the tests: It only includes name, version, description, scripts, and dependencies.