ts-safeql / safeql

Validate and auto-generate TypeScript types from raw SQL queries in PostgreSQL.
https://safeql.dev
MIT License
1.35k stars 22 forks source link

Unable to install using npm #255

Closed Vishal-beep136 closed 2 months ago

Vishal-beep136 commented 3 months ago

Describe the bug I can't install using npm by this script

npm install --save-dev @ts-safeql/eslint-plugin libpg-query

does this library require Python to be installed on the machine??

because I got this error ->

npm warn deprecated npmlog@5.0.1: This package is no longer supported.
npm warn deprecated are-we-there-yet@2.0.0: This package is no longer supported.
npm warn deprecated gauge@3.0.2: This package is no longer supported.

npm error code 1
npm error path D:\app\backend-nestjs\node_modules\libpg-query
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node-pre-gyp install --fallback-to-build        
npm error Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\USER NAME\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=D:\app\backend-nestjs\node_modules\libpg-query\build\Release\queryparser.node --module_name=queryparser --module_path=D:\app\backend-nestjs\node_modules\libpg-query\build\Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v115' (1)
npm error node-pre-gyp info it worked if it ends with ok
npm error node-pre-gyp info using node-pre-gyp@1.0.11
npm error node-pre-gyp info using node@20.16.0 | win32 | x64
npm error node-pre-gyp info check checked for "D:\app\backend-nestjs\node_modules\libpg-query\build\Release\queryparser.node" (not found)
npm error node-pre-gyp http GET https://supabase-public-artifacts-bucket.s3.amazonaws.com/libpg-query-node/queryparser-v16.2.0-node-v115-win32-x64.tar.gz
npm error node-pre-gyp ERR! install response status 404 Not Found on https://supabase-public-artifacts-bucket.s3.amazonaws.com/libpg-query-node/queryparser-v16.2.0-node-v115-win32-x64.tar.gz
npm error node-pre-gyp WARN Pre-built binaries not installable for libpg-query@16.2.0 and node@20.16.0 (node-v115 ABI, unknown) (falling back to source compile with node-gyp)
npm error node-pre-gyp WARN Hit error response status 404 Not Found on https://supabase-public-artifacts-bucket.s3.amazonaws.com/libpg-query-node/queryparser-v16.2.0-node-v115-win32-x64.tar.gz
npm error gyp info it worked if it ends with ok
npm error gyp info using node-gyp@10.1.0
npm error gyp info using node@20.16.0 | win32 | x64
npm error gyp info ok
npm error gyp info it worked if it ends with ok
npm error gyp info using node-gyp@10.1.0
npm error gyp info using node@20.16.0 | win32 | x64
npm error gyp ERR! find Python
npm error gyp ERR! find Python Python is not set from command line or npm configuration
npm error gyp ERR! find Python Python is not set from environment variable PYTHON
npm error gyp ERR! find Python checking if the py launcher can be used to find Python 3
npm error gyp ERR! find Python - executable path is ""
npm error gyp ERR! find Python - "" could not be run
npm error gyp ERR! find Python checking if "python3" can be used
npm error gyp ERR! find Python - executable path is ""
npm error gyp ERR! find Python - "" could not be run
npm error gyp ERR! find Python checking if "python" can be used
npm error gyp ERR! find Python - executable path is ""
npm error gyp ERR! find Python - "" could not be run
npm error gyp ERR! find Python checking if Python is C:\Users\USER NAME\AppData\Local\Programs\Python\Python311\python.exe
npm error gyp ERR! find Python - version is ""
npm error gyp ERR! find Python - version is  - should be >=3.6.0
npm error gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
npm error gyp ERR! find Python - "C:\Users\USER NAME\AppData\Local\Programs\Python\Python311\python.exe" could not be run
npm error gyp ERR! find Python checking if Python is C:\Program Files\Python311\python.exe
npm error gyp ERR! find Python - version is ""
npm error gyp ERR! find Python - version is  - should be >=3.6.0
npm error gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
npm error gyp ERR! find Python - "C:\Program Files\Python311\python.exe" could not be run
npm error gyp ERR! find Python checking if Python is C:\Users\USER NAME\AppData\Local\Programs\Python\Python311-32\python.exe

Desktop (please complete the following information):

Newbie012 commented 3 months ago

since there's no pre-compiled libpg-query build for your OS (Windows 11), it tries to compile it on your end using Python. Although, it appears like you don't have Python installed on your machine

karlhorky commented 3 months ago

To get Python and other build tools installed on Windows, you may want to consider installing Chocolatey

If you did this, you could use the following command to install python and visualstudio2022-workload-vctools:

choco install python visualstudio2022-workload-vctools -y
karlhorky commented 3 months ago

@Vishal-beep136 one thing to consider on Windows is that you may need to use libpg-query version 16.2.0, if the U1052: file 'Makefile.msvc' not found errors from nmake reported in this issue is still valid:

Vishal-beep136 commented 3 months ago

To get Python and other build tools installed on Windows, you may want to consider installing Chocolatey

If you did this, you could use the following command to install python and visualstudio2022-workload-vctools:

choco install python visualstudio2022-workload-vctools -y

wouldn't it work if I install python manually or from python official site??

karlhorky commented 3 months ago

Yes, should also work πŸ‘ I just personally avoid downloading programs from websites, as it's slower, more manual work and easier to run into security problems. Using a command line package manager improves all of these things.

Vishal-beep136 commented 3 months ago

Yes, should also work πŸ‘ I just personally avoid downloading programs from websites, as it's slower, more manual work and easier to run into security problems. Using a command line package manager improves all of these things.

@karlhorky Thanks for the response! Do I also need to install this visualstudio2022-workload-vctools

Vishal-beep136 commented 3 months ago

@karlhorky I used chocolatey to install and it seems that it worked thanks :))

Vishal-beep136 commented 3 months ago

@Newbie012 @karlhorky Btw it would be better if you mention in docs/readme that Python is required at least for windows OS I believe.

Anyway thanks again!!

Newbie012 commented 3 months ago

PRs are welcome πŸ™‚

karlhorky commented 3 months ago

@Vishal-beep136 if you think that you could do a PR to add the section to the readme + docs, then I would suggest these 2 places:

  1. A new Windows paragraph + code block in "Prerequisites" on the Getting Started docs page Screenshot 2024-08-19 at 17 35 46
  2. If the Readme should be updated, consider 2 possibilities:
    1. Remove the npm install code block from the Readme completely and only leave the link to the docs (maybe even remove the Install section)
    2. Add a new Prerequisites section, copied from the docs page, including the docs content and also the new Windows content that you're proposing Screenshot 2024-08-19 at 17 35 56

If you think that you don't have time for this, maybe you can open a new issue with these as proposals :) Otherwise this will probably be lost in this closed issue.

Vishal-beep136 commented 3 months ago

@karlhorky Well rn I don't have much time but I might consider adding PR if I got free time Otherwise I might create a new issue as you mentioned! or rather should I reopen this issue itself??

karlhorky commented 3 months ago

New issue is better, please :)

Vishal-beep136 commented 3 months ago

@karlhorky @Newbie012

Heyy I was able to install successfully @ts-safeql/eslint-plugin libpg-query without any errors however it doesn't seems to work, like it's not linting or showing error. I'm using it with Prisma.

I followed this doc prisma

const query = prisma.$queryRaw`SELECT idd FROM users`;

it should display error like -> Error: column "idd" does not exist

I'm not sure what went wrong I believe I've even configured it correct in .eslintrc.js

 module.exports = { 
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin', '@ts-safeql/eslint-plugin'],
  rules: {
    ....
    '@ts-safeql/check-sql': [
      'error',
      {
        connections: [
          {
            connectionUrl: process.env.DATABASE_URL,
            migrationsDir: './prisma/migrations',
            targets: [
              { tag: 'prisma.+($queryRaw|$executeRaw)', transform: '{type}[]' },
            ],
          },
        ],
      },
    ],
  },
 }

also EsLint is crashing a lot

[Info  - 12:20:26 PM] ESLint server running in node v20.14.0
[Info  - 12:20:26 PM] ESLint server is running.
[Info  - 12:20:27 PM] ESLint library loaded from: D:\app\backend-nestjs\node_modules\eslint\lib\api.js
migrationPath D:\app\backend-nestjs\prisma\migrations
[Error - 12:20:39 PM] Server process exited with code 3765269347.
[Error - 12:20:39 PM] The ESLint server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Info  - 12:20:39 PM] ESLint server stopped.

Could be that @ts-safeql/eslint-plugin libpg-query aren't compatible with windows OS 😭 ?? or Am I missing something ??

Thanks :)

karlhorky commented 3 months ago

@Vishal-beep136 we'll take a look and respond here.

In the meantime, if you could take a few minutes to open the new docs issue described above, then we can make sure to not lose the proposed documentation changes πŸ‘

Vishal-beep136 commented 3 months ago

@karlhorky I'm thinking of doing PR should I change contents in docs/ folder or readme.md

karlhorky commented 3 months ago

Probably both, check out my comment above

karlhorky commented 2 months ago

@Vishal-beep136 if the PR is too much, you can also just create an issue for it, documenting the ideas from:

karlhorky commented 2 months ago

Ah I managed to miss your PR and this issue slipped down my list, I see it now here:

I'll take a look at this and your new issue above today.

karlhorky commented 2 months ago

@Vishal-beep136 Closing this issue - I've opened a new issue for the Prisma error you reported above: