`mjs` config file does not work
yamatatsu opened this issue · comments
Describe the bug
vitest-environment-dynalite-config.mjs
does not work.
To Reproduce
Steps to reproduce the behavior:
- create
mjs
config fileexport default { // configures }
- run test
And following error will be shown:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL main.test.ts [ main.test.ts ]
Error: Something went wrong reading your vitest-environment-dynalite-config.mjs: Unexpected token 'export', SyntaxError: Unexpected token 'export'
at readConfig (/Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/packages/vitest-environment-dynalite/dist/index.mjs:86:36)
at getDynalitePort (/Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/packages/vitest-environment-dynalite/dist/index.mjs:102:30)
at setEnvironmentVariables (/Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/packages/vitest-environment-dynalite/dist/index.mjs:130:16)
at /Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/packages/vitest-environment-dynalite/dist/index.mjs:245:1
at VitestExecutor.runModule (file:///Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/node_modules/.pnpm/vite-node@1.5.2_@types+node@18.14.5/node_modules/vite-node/dist/client.mjs:362:5)
at VitestExecutor.directRequest (file:///Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/node_modules/.pnpm/vite-node@1.5.2_@types+node@18.14.5/node_modules/vite-node/dist/client.mjs:346:5)
at VitestExecutor.cachedRequest (file:///Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/node_modules/.pnpm/vite-node@1.5.2_@types+node@18.14.5/node_modules/vite-node/dist/client.mjs:189:14)
at VitestExecutor.executeId (file:///Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/node_modules/.pnpm/vite-node@1.5.2_@types+node@18.14.5/node_modules/vite-node/dist/client.mjs:165:12)
at runSetupFiles (file:///Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/node_modules/.pnpm/@vitest+runner@1.5.2/node_modules/@vitest/runner/dist/index.js:592:7)
at collectTests (file:///Users/yamamoto.tatsuya/Projects/vitest-environment-dynalite/node_modules/.pnpm/@vitest+runner@1.5.2/node_modules/@vitest/runner/dist/index.js:615:7)
❯ readConfig ../vitest-environment-dynalite/dist/index.mjs:86:36
84| return JSON.parse(fs.readFileSync(file, "utf-8"));
85| }
86| const importedConfig = eval(fs.readFileSync(file, "utf-8"));
| ^
87| if ("default" in importedConfig) {
88| return importedConfig.default;
❯ getDynalitePort ../vitest-environment-dynalite/dist/index.mjs:102:30
❯ setEnvironmentVariables ../vitest-environment-dynalite/dist/index.mjs:130:16
❯ ../vitest-environment-dynalite/dist/index.mjs:245:1
❯ readConfig ../vitest-environment-dynalite/dist/index.mjs:93:13
❯ getDynalitePort ../vitest-environment-dynalite/dist/index.mjs:102:30
❯ setEnvironmentVariables ../vitest-environment-dynalite/dist/index.mjs:130:16
❯ ../vitest-environment-dynalite/dist/index.mjs:245:1
Module Error: Something went wrong reading your vitest-environment-dynalite-config.mjs: Unexpected token 'export', SyntaxError: Unexpected token 'export' seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "Error: Something went wrong reading your vitest-environment-dynalite-config.mjs: Unexpected token 'export', SyntaxError: Unexpected token 'export'" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
As a temporary workaround you can try to inline the package by updating your config:
// vitest.config.js
export default {
test: {
server: {
deps: {
inline: [
"Error: Something went wrong reading your vitest-environment-dynalite-config.mjs: Unexpected token 'export', SyntaxError: Unexpected token 'export'"
]
}
}
}
}
Expected behavior
run test successfully
I've created a fork of this library to use dynamo-db-local (dynalite doesn't support TransactWriteItems), and ended up using import-sync to workaround this issue: dgadelha@a2b9b68
@dgadelha
It seems so good! Thank you so much! 😍