Closed vlinder closed 3 weeks ago
Hi there 👋 Can you provide the error logs you get (+ jest version)? We use jest for unit tests and do not have any issues with it.
We currently use version 29.7.0
of jest.
I guess jest can be configured in a lot of ways. I see no reason to fight against it if avoidable.
Here is the error message:
Details:
/Volumes/SourceCode/web/node_modules/.pnpm/@xenova+transformers@2.17.2/node_modules/@xenova/transformers/src/env.js:49
const __dirname = RUNNING_LOCALLY ? _path.default.dirname(_path.default.dirname(_url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()))) : './';
^
SyntaxError: Identifier '__dirname' has already been declared
I think it is because it converts the module to CommonJS.
This is what the node manual says:
The following variables may appear to be global but are not. They exist only in the scope of CommonJS modules:
- __dirname
- ...
So since they are set 'in scope' you cannot redeclare them.
I tried this with a minimal test file
const __dirname = 1;
$ node test.js
/Volumes/SourceCode/test.js:1
const __dirname = 1;
^
SyntaxError: Identifier '__dirname' has already been declared
Any blockers to merge this?
@vlinder & @xenova this is also blocking drizzle-kit from completing successfully.
const __dirname = RUNNING_LOCALLY ? import_path.default.dirname(import_path.default.dirname(import_url.default.fileURLToPath(__esbuild_register_import_meta_url__))) : "./";
^
SyntaxError: Identifier '__dirname' has already been declared
at wrapSafe (node:internal/modules/cjs/loader:1281:20)
at Module._compile (node:internal/modules/cjs/loader:1321:27)
at extensions..js (project\node_modules\.pnpm\drizzle-kit@0.24.2\node_modules\drizzle-kit\bin.cjs:17218:20)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Module.require (node:internal/modules/cjs/loader:1233:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (project\node_modules\.pnpm\@xenova+transformers@2.17.2\node_modules\@xenova\transformers\src\utils\hub.js:11:21)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at extensions..js (project\node_modules\.pnpm\drizzle-kit@0.24.2\node_modules\drizzle-kit\bin.cjs:17218:20)
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Running
jest
with this package crashes because of redeclaration of reserved keyword__dirname
.This PR renames it to
dirname__
.