Description
Search Terms
ReferenceError: __values is not defined
tslib
noEmitHelpers
importHelpers
Expected Behavior
An error message which helps me solve the problem. Could be something along the lines of what's described in #1504 (When transpiled code attempts to require tslib, regenerator-runtime, or @swc/helpers, log a helpful warning about adding those dependencies; link to relevant docs page), making sure to include this case in the docs, or could be logic to actually detect this situation and suggest a solution.
Specifically, the problem here is that noEmitHelpers
means tslib
helpers aren't included during compilation. Normally that's fine, as long as you have importHelpers
turned on, but if you have no other imports or exports (require
calls don't count), importHelpers
does you no good, even with tslib
added as an explicit dependency. The solution (in my case) was to convert my require
s to import
s, which I hadn't yet gotten around to in converting my script from JS to TS. (Presumably turning off noEmitHelpers
would also work.) This is the comment which finally saved me.
Actual Behavior
The raw error, with no explanation, not even that this is a tslib
problem:
/Users/Katie/Documents/Sentry/forks/ts-node-repros/example.ts:1
for (const num of [1, 2, 3]) {
^
ReferenceError: __values is not defined
at Object.<anonymous> (/Users/Katie/Documents/Sentry/forks/ts-node-repros/example.ts:1:19)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Module.m._compile (/Users/Katie/Documents/Sentry/forks/ts-node-repros/node_modules/ts-node/src/index.ts:1455:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Object.require.extensions.<computed> [as .ts] (/Users/Katie/Documents/Sentry/forks/ts-node-repros/node_modules/ts-node/src/index.ts:1458:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at phase4 (/Users/Katie/Documents/Sentry/forks/ts-node-repros/node_modules/ts-node/src/bin.ts:567:12)
at bootstrap (/Users/Katie/Documents/Sentry/forks/ts-node-repros/node_modules/ts-node/src/bin.ts:85:10)
error Command failed with exit code 1.
Steps to reproduce the problem
- Create a script with no imports or exports, which needs a
tslib
helper when down-compiled - Set
noEmitHelpers
set totrue
in yourtsconfig
- Try to run the script with
ts-node
- Get the error above
Minimal reproduction
(See also TypeStrong/ts-node-repros#26)
example.ts:
// possibly `require` calls, but no imports
for (const num of [1, 2, 3]) {
console.log(num);
}
tsconfig.json:
{
"compilerOptions": {
"downlevelIteration": true,
// this isn't necessary to cause the error but does make the problem harder to track down
// "importHelpers": true,
"noEmitHelpers": true
}
}
Then run:
yarn add -D ts-node typescript
yarn add -D tslib # not necessary to cause the error but also makes it harder to figure out
ts-node example.ts
Specifications
Versions:
> yarn ts-node -vv
ts-node v10.7.0
node v16.14.0
compiler v4.6.2
tsconfig.json:
{
"compilerOptions": {
"downlevelIteration": true,
// this isn't necessary to cause the error but does make the problem harder to track down
// "importHelpers": true,
"noEmitHelpers": true
}
}
Operating system and version: OS X 12.2.1