Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from 1.12.9 to 1.12.14: compatibility issues in Nuxt/TypeScript & "config" package #56

Closed
INRIX-Iurii-Okhmat opened this issue Jan 27, 2022 · 1 comment

Comments

@INRIX-Iurii-Okhmat
Copy link

INRIX-Iurii-Okhmat commented Jan 27, 2022

I've got a Nuxt app that uses "config" (https://www.npmjs.com/package/config) module. Config files are ".ts". Config is imported in nuxt.config.ts to get environment-specific configuration.

Everything was working fine with v1.12.9, upgrading to v1.12.14 produces the following error.

 FATAL  Cannot parse config file: '/Users/‡‡‡‡‡‡‡‡‡‡‡‡‡‡/ui/config/default.ts': SyntaxError: Unexpected token 'export'

  at Config.util.parseFile (node_modules/config/lib/config.js:844:11)
  at node_modules/config/lib/config.js:644:26
  at Array.forEach (<anonymous>)
  at Config.util.loadFileConfigs (node_modules/config/lib/config.js:643:16)
  at new Config (node_modules/config/lib/config.js:116:27)
  at node_modules/config/lib/config.js:1492:31
  at jiti (node_modules/jiti/dist/jiti.js:1:196050)
  at nuxt.config.ts:3:38
  at jiti (node_modules/jiti/dist/jiti.js:1:196050)
  at Object.loadNuxtConfig (node_modules/@nuxt/config/dist/config.js:1082:15)

  ╭──────────────────────────────────────────────────────────╮
  │                                                                                
  │   ✖ Nuxt Fatal Error                                                           
  │                                                                                
  │   Error: Cannot parse config file:                                             
  │   '/Users/‡‡‡‡‡‡‡‡‡‡‡‡‡‡/ui/config/default.ts':   							   
  │   SyntaxError: Unexpected token 'export'                                       
  │                                                                                
 ╰──────────────────────────────────────────────────────────╯

You can find a sample project here: https://github.com/INRIX-Iurii-Okhmat/jiti-config-issue-repro
It has a package-lock with latest (1.12.14) version: https://github.com/INRIX-Iurii-Okhmat/jiti-config-issue-repro/blob/933dc181f81c4fa21f97eabc3479c69ac27445f7/package-lock.json#L6112

Downgrading to 1.12.9 fixes the issue

"jiti": {
            "version": "1.12.9",
            "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.12.9.tgz",
            "integrity": "sha512-TdcJywkQtcwLxogc4rSMAi479G2eDPzfW0fLySks7TPhgZZ4s/tM6stnzayIh3gS/db3zExWJyUx4cNWrwAmoQ=="
}

NodeJS: v12.
Nuxt version: 2.15.7

@INRIX-Iurii-Okhmat INRIX-Iurii-Okhmat changed the title Upgrading from 1.12.9 to 1.12.14 broke not compatible with "config" NPM module (within Nuxt) Upgrading from 1.12.9 to 1.12.14: compatibility issues in Nuxt/TypeScript & "config" package Jan 27, 2022
@pi0 pi0 closed this as completed in 2ddcb8a Jan 28, 2022
@pi0
Copy link
Member

pi0 commented Jan 28, 2022

Hi @INRIX-Iurii-Okhmat. Thanks for issue and reprotuction. I've added a hotfix as jiti@1.12.15 which you can get by recreating lockfile. However, please consider that config npm package does not support typescript (for files in config/ directory). ts support in config/ with jiti might be broken in the future versions.


Details:

Interestingly your setup was working before because jiti was wrongly transpiling config package itself and implicitly adding typescript support to its loader require call. When the new version fixed that and use native CJS, it got broken!

1.12.14:

[jiti] [transpile] /home/pooya/tmp/jiti-config-issue-repro/nuxt.config.ts                                                                                                                                                                                              12:55:07
[jiti] [cache hit] /home/pooya/tmp/jiti-config-issue-repro/nuxt.config.ts ~> /tmp/node-jiti/jiti-config-issue-repro-nuxt.config.ts.7ce25370.js                                                                                                                         12:55:07
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/lib/config.js                                                                                                                                                                              12:55:07
[jiti] Native require error: Cannot parse config file: '/home/pooya/tmp/jiti-config-issue-repro/config/default.ts': SyntaxError: Unexpected token 'export'                                                                                                             12:55:08

  at Config.util.parseFile (node_modules/config/lib/config.js:844:11)
  at node_modules/config/lib/config.js:644:26
  at Array.forEach (<anonymous>)
  at Config.util.loadFileConfigs (node_modules/config/lib/config.js:643:16)
  at new Config (node_modules/config/lib/config.js:116:27)
  at Object.<anonymous> (node_modules/config/lib/config.js:1492:31)
  at Module._compile (internal/modules/cjs/loader.js:1085:14)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
  at Module.load (internal/modules/cjs/loader.js:950:32)
  at Function.Module._load (internal/modules/cjs/loader.js:790:12)
[jiti] [fallback] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/lib/config.js                                                                                                                                                                            12:55:08
[jiti] [cache hit] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/lib/config.js ~> /tmp/node-jiti/lib-config.js.ff39efc7.js                                                                                                                               12:55:08

 FATAL  Cannot parse config file: '/home/pooya/tmp/jiti-config-issue-repro/config/default.ts': SyntaxError: Unexpected token 'export'                                                                                                              12:55:08

1.12.9:

[jiti] [transpile] /home/pooya/tmp/jiti-config-issue-repro/nuxt.config.ts                                                                                                                                                                                                    12:56:23
[jiti] [cache hit] /home/pooya/tmp/jiti-config-issue-repro/nuxt.config.ts ~> /tmp/node-jiti/jiti-config-issue-repro-nuxt.config.ts.7ce25370.js                                                                                                                               12:56:23
[jiti] [transpile] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/lib/config.js                                                                                                                                                                                 12:56:23
[jiti] [cache hit] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/lib/config.js ~> /tmp/node-jiti/lib-config.js.ff39efc7.js                                                                                                                                     12:56:23
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/defer.js                                                                                                                                                                                         12:56:23
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/raw.js                                                                                                                                                                                           12:56:23
[jiti] [transpile] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/parser.js                                                                                                                                                                                     12:56:23
[jiti] [cache miss] /home/pooya/tmp/jiti-config-issue-repro/node_modules/config/parser.js                                                                                                                                                                                    12:56:23
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/ts-node/dist/index.js                                                                                                                                                                                   12:56:23
[jiti] [transpile] /home/pooya/tmp/jiti-config-issue-repro/config/default.ts                                                                                                                                                                                                 12:56:23
[jiti] [cache miss] /home/pooya/tmp/jiti-config-issue-repro/config/default.ts                                                                                                                                                                                                12:56:23
[jiti] [transpile] /home/pooya/tmp/jiti-config-issue-repro/node_modules/@nuxt/typescript-build/dist/index.js                                                                                                                                                                 12:56:23
[jiti] [cache miss] /home/pooya/tmp/jiti-config-issue-repro/node_modules/@nuxt/typescript-build/dist/index.js                                                                                                                                                                12:56:23
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/@nuxt/loading-screen/lib/module.js                                                                                                                                                                      12:56:24
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/@nuxt/components/dist/index.js                                                                                                                                                                          12:56:24
[jiti] [native] /home/pooya/tmp/jiti-config-issue-repro/node_modules/@nuxt/telemetry/dist/index.js     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants