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

TypeError: Cannot read property 'endsWith' of undefined gets thrown in windows when "npm init @vitejs/app" is invoked #2568

Closed
capaj opened this issue Mar 17, 2021 · 10 comments
Labels
bug: upstream Bug in a dependency of Vite

Comments

@capaj
Copy link

capaj commented Mar 17, 2021

Describe the bug

TypeError is thrown on Windows 10 system shell

Reproduction

just run npm init @vitejs/app

System Info

  • vite version: not sure
  • Operating System: Windows 10
  • Node version: 15.11.0
  • Package manager (npm/yarn/pnpm) and version:
    npm7.6.0

Logs (Optional if provided reproduction)

PS C:\Users\capaj\OneDrive\Dokumenty\GitHub\react-tweet-embed> node -v     
v15.11.0
PS C:\Users\capaj\OneDrive\Dokumenty\GitHub\react-tweet-embed> npm init @vitejs/app
npm notice 
npm notice New patch version of npm available! 7.6.0 -> 7.6.3       
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.6.3
npm notice Run npm install -g npm@7.6.3 to update!
npm notice 
Need to install the following packages:
  @vitejs/create-app
Ok to proceed? (y) y
C:\Users\capaj\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\kolorist\dist\cjs\index.js:25
        if (TERM.endsWith('-256color')) {
                 ^

TypeError: Cannot read property 'endsWith' of undefined
    at Object.<anonymous> (C:\Users\capaj\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\kolorist\dist\cjs\index.js:25:18)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (C:\Users\capaj\AppData\Local\npm-cache\_npx\9c7583f20b80c4d1\node_modules\@vitejs\create-app\index.js:16:5)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
npm notice
npm notice New patch version of npm available! 7.6.0 -> 7.6.3
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.6.3
npm notice Run npm install -g npm@7.6.3 to update!
npm notice
npm ERR! code 1
npm ERR! path C:\Users\capaj\OneDrive\Dokumenty\GitHub\react-tweet-embed
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c create-app

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\capaj\AppData\Local\npm-cache\_logs\2021-03-17T20_02_37_486Z-debug.log
PS C:\Users\capaj\OneDrive\Dokumenty\GitHub\react-tweet-embed> 
@alesvaupotic
Copy link
Contributor

set TERM=ansi solves it temporarily. Probably any value will do, as it fails on undefined TERM.

@ghost
Copy link

ghost commented Mar 17, 2021

Same.
I see it in Powershell, but it works in Git Bash.

@jeremio
Copy link
Contributor

jeremio commented Mar 17, 2021

Same here.
Operating System: Windows 10 64bits
Node version: 14.16.0
Npm: 6.14.11
nvm-windows: 1.1.7

@bjarkihall
Copy link

bjarkihall commented Mar 17, 2021

kolorist assumes env variable is already defined before essentially doing undefined.endswith.

It had this commited and released 3 hours ago (as 1.3.0 and create-app has dependency on "^1.2.9"):
marvinhagemeister/kolorist@ec85371#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80

Which causes a runtime error when the module is required.
It can be resolved by pinning a stable version of kolorist in @vite/create-app (to prevent kolorist from being able to break vite installs again) and/or by submitting a PR with a fix for 1.3.1 to kolorist.

edit: I just prepared a PR.

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented Mar 17, 2021

Whoops, that's on me! Only tested the changes on MacOS + Linux, but not on Windows. Sorry for the trouble this has caused. Just merged the PR and published a new version with the fix. Thanks to @bjarkihall for submitting a fix 👍

@bjarkihall
Copy link

bjarkihall commented Mar 17, 2021

Sorry but I seem to get "SyntaxError: Unexpected token '.'" at the same place now.. which is a bit odd:

supportLevel = TERM?.endsWith('-256color')
                            ^

SyntaxError: Unexpected token '.'
    at Module._compile (internal/modules/cjs/loader.js:892:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (C:\Users\myusername\AppData\Roaming\npm-cache\_npx\14280\node_modules\@vitejs\create-app\index.js:16:5)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)

Is optional chaining not supported or am I missing something obvious?
edit: guess it's because I'm still running node 12, maybe it's better to just fall back to
"supportLevel = TERM && TERM.endsWith('-256color')", for the time being so more users don't fall into this?
I thought at first sight that the repo had a lower compilation target.

@marvinhagemeister
Copy link
Contributor

Just booted up my windows machine and I can confirm that it works now, even when downgrading to Node 12.

@bjarkihall
Copy link

I can also confirm it runs smoothly now on windows regardless of the node version (12 and upwards).

@yyx990803
Copy link
Member

I assume this is fixed by kolorist 1.3.2?

@marvinhagemeister
Copy link
Contributor

yup

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet
Development

No branches or pull requests

7 participants