lokalise / i18n-ally

🌍 All in one i18n extension for VS Code
https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally
MIT License
3.79k stars 301 forks source link

TS parser not working anymore (TS5095: Unable to compile TypeScript) #709

Open Alfagun74 opened 2 years ago

Alfagun74 commented 2 years ago

Describe the bug I18N-Ally cant parse my translation files anymore. I use Svelte and Typescript Translation Files. See Error below.

It used to work before, now it doesnt ¯_(ツ)_/¯.

Extension Version v2.8.1

Framework/i18n package you are using Svelte, Typescript-Parser

Device Infomation

Extension Log Go to View -> Output -> i18n Ally, and paste the content below. You should mask any sensitive information

🈶 Activated, v2.8.1

――――――

💼 Workspace root changed to "c:\project"
🌞 Enabled
🧩 Enabled frameworks: Svelte
🧬 Enabled parsers: ts

📈 Telemetry id: 2a7c1185-c100-48f4-8684-b148e8ffe963
🚀 Initializing loader "c:\project"
📂 Directory structure: file
🗃 Path Matcher Regex: /^(?<locale>[\w-_]+)\.(?<ext>ts)$/

📂 Loading locales under c:\project\src\i18n
    📑 Loading (de) de.ts [1639728684800.5498]
        🐛 Failed to load Error: Command failed: node "c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\dist\bin.js" --dir "c:\project" --transpile-only --compiler-options "{\"importHelpers\":false,\"allowJs\":true,\"module\":\"commonjs\"}" "c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\assets\loader.js" "c:\project\src\i18n\de.ts"

c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:513
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'preserveValueImports' can only be used when 'module' is set to 'es2015' or later.

    at createTSError (c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:513:12)
    at reportTSError (c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:517:19)
    at getOutput (c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:955:34)
    at Object.compile (c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:968:32)
    at Module.m._compile (c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:1056:42)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .js] (c:\Users\Someone\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\src\index.ts:1059: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:81:12)
terales commented 2 years ago

@Alfagun74 we haven't released any updates so far. Have you updated the VS Code itself recently?

Alfagun74 commented 2 years ago

@terales im running on the latest version 1.63.2

RobertSasak commented 2 years ago

I think this issue is connected to config parsersTypescriptTsNodePath which expects _nodemodules/ts-node/dist/bin.js. I solved the issue by installing ts-node.

yarn add -D ts-node

However I still wonder how what value I need to provide to use global installation of ts-node.

qyvip commented 2 years ago

I also encountered this situation. It happened after upgrading vscode. The current version of vscode is 1.66.2 (Universal). After searching for a long time, I saw this issue and finally ran to the plugin directory [~/.vscode/ extensions/lokalise.i18n-ally-2.8.1/] executed "yarn add -D ts-node", and after retrying, it was successful. It seems that a compatible version still needs to be released, thanks

Coretteket commented 1 year ago

I had the same issue, but solving it for me was a little more involved: Running yarn add -D ts-node failed, because yarn couldn't find fluent-vue-cli. Luckily, removing that dependency didn't seem to break things. Then, I got a new error in my output:

🐛 Failed to load Error: Command failed: node "c:\Users\Qcoret\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\dist\bin.js" --dir "c:\Users\Qcoret\Documents\qntn.io" --transpile-only --compiler-options "{\"importHelpers\":false,\"allowJs\":true,\"module\":\"commonjs\"}" "c:\Users\Qcoret\.vscode\extensions\lokalise.i18n-ally-2.8.1\assets\loader.js" "c:\Users\Qcoret\Documents\qntn.io\src\i18n\loader.ts"
c:\Users\Qcoret\.vscode\extensions\lokalise.i18n-ally-2.8.1\node_modules\ts-node\dist-raw\node-internal-errors.js:46
const err = new Error(getErrRequireEsmMessage(filename, parentPath, packageJsonPath))
              ^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: c:\Users\Qcoret\Documents\qntn.io\src\scripts\flatten.ts
require() of ES modules is not supported.
require() of c:\Users\Qcoret\Documents\qntn.io\src\scripts\flatten.ts from c:\Users\Qcoret\Documents\qntn.io\src\i18n\loader.ts is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from c:\Users\Qcoret\Documents\qntn.io\package.json.

I ended up creating a phantom package.json in my src/i18n folder, without a "type": "module" (and immediately added the file to my .gitignore and vscode ignore). That seems to have resolved the issue, but this certainly seems like something that should/could be fixed on the package level.

HenryChow505 commented 3 weeks ago

In setting the json, you need to set up i18n-ally.parsers.typescript.com pilerOptions values

image