Repository navigation
SafeQL installation fails on Windows #80
Description
Activity
That's not exactly an issue of SafeQL, but libpg-query.
One of my machines is using Windows, but all of the development occurs in WSL (Windows Subsystem for Linux) and it seems to work fine.
Another workaround that I can think of is using Docker.
I'll take a look at https://github.com/taozhi8833998/node-sql-parser as well
Reacted by Karl Horky and Victor Ejike NwosuI ran some tests, and it looks like
node-sql-parserisn't working as expected. It fails to parse many syntaxes such as:SELECT ((colname + INTERVAL '1 month')::DATE - 1) as x
If I change it to this (which I believe will result in a runtime error; haven't checked):
SELECT (colname + INTERVAL '1 month')::DATE - 1 as x
it will throw an error.
I believe we should stick with
libpg-querysince it uses the real PostgreSQL query parser. Let's see how the conversation in constructive-io/libpg-query-node#22 evolves.Reacted by Pasecinic NichitaAny chance you could mention that this doesn't work on Windows on your website and/or the readme file? Just spent a good amount of time trying to figure out why this wasn't installing.
I am looking forward to using it someday!
- Reacted by Karl Horky and swax
@gregnr opened a PR using
emnapi+ WebAssembly to getlibpg_querysupport on Windows 👀 🔥 (in thelibpg-querynpm package)Reacted by Eliya Cohen, poke and swaxHopefully should be resolved if Hilzu/libpg-query-node#11 will be resolved as well.
Thanks to @lfittl
libpg_query@16-5.1.0now has support for compiling on Windows too 🎉 🚀There's a PR by @aquariuslt open in
libpg-querynow 👀 🙌The PR has been merged and published as
libpg-query@16.1.0- installable on Windows, finally!Reacted by poke and Lukas Fittl@Eprince-hub can you confirm that SafeQL performs checking and shows errors and warnings on Windows now?
Just trying out the new
libpg-query@16.1.0Windows version on a GitHub Actionswindows-latestrunner, and it looks like there's a newERR_UNSUPPORTED_ESM_URL_SCHEMEerror with SafeQL regardless of whether a linting problem is encountered or not:pnpm eslint . --max-warnings 0 Oops! Something went wrong! :( ESLint: 8.57.0 Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:' at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11) at defaultLoad (node:internal/modules/esm/load:130:3) at ModuleLoader.load (node:internal/modules/esm/loader:409:13) at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:56) at new ModuleJob (node:internal/modules/esm/module_job:65:26) at #createModuleJob (node:internal/modules/esm/loader:303:17) at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:260:34) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:17) at async ModuleLoader.import (node:internal/modules/esm/loader:328:23) Error: Process completed with exit code 1.This appears to be related to the Node.js requirement on Windows to "need to write
file:///c:/x/y/zinstead ofc:/x/y/z"There are no ESM errors or warnings from the ESLint run on Windows when SafeQL is disabled:
So this appears to be a SafeQL-specific bug with Windows support.
cc @Newbie012
Reacted by Eliya CohenActually, looking at this closer and trying to create a reproduction, it looks like it's something else in
eslint-config-upleveledthat's causing it, since a simple SafeQL config seems to work:upleveled/preflight-test-project-next-js-passing#156 (comment)
Edit: Yes confirmed, the problem with
ERR_UNSUPPORTED_ESM_URL_SCHEMEwas an error in our owneslint-config-upleveledpackage:It seems like using
process.cwd()in a dynamicimport()doesn't work on Windows, have to usepathToFileURL:+import { pathToFileURL } from 'node:url'; -await import(`${process.cwd()}/package.json`, { +await import(pathToFileURL(`${process.cwd()}/package.json`).href, { assert: { type: 'json' }, });
I have now successfully been able to receive a SafeQL error on GitHub Actions, on a Windows runner 🎉
await sql` INSERT INTO loogos (name) VALUES ('Next.js'), ('Next.js'), ('Next.js'), ('Next.js') `;
SafeQL error:
$ pnpm eslint . --max-warnings 0 (node:2004) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time (Use `node --trace-warnings ...` to show where the warning was created) D:\a\preflight-test-project-next-js-passing\preflight-test-project-next-js-passing\migrations\00000-create-table-logos.ts Error: 25:7 error Invalid Query: relation "loogos" does not exist @ts-safeql/check-sql ✖ 1 problem (1 error, 0 warnings) Error: Process completed with exit code 1.
- Workflow run: https://github.com/upleveled/preflight-test-project-next-js-passing/actions/runs/8566529267/job/23476453817?pr=156
While testing the Windows SafeQL issue, I created a cross-platform PostgreSQL + SafeQL reproduction repo (Windows, macOS and Linux runners).
Now that I solved it, I thought this may also be a useful thing for users of the SafeQL project longer term (eg. for users demonstrating their bugs):
cc @Newbie012 , in case we should integrate this into the issue workflow on GitHub.
@Eprince-hub if you could do one more check from your side on your Windows system, then I think this issue can be closed.
Reacted by Victor Ejike Nwosu@karlhorky
SafeQL linting error message on Windows ComputerBecause of the issue with a long path not being found by node on Windows: nodejs/node#50753
I needed to run the two scripts below to get it working
echo 'node-linker=hoisted' > ./.npmrc
pnpm install --force
I will be closing this issue as it is now confirmed that SafeQL can be installed and used on Windows Machines
Reacted by Karl HorkyReacted by Karl Horky


Describe the bug
SafeQL can not be installed on Windows 10 / 11. This is due to one of the dependencies,
libpg-querythat doesn't currently support installation on windows machines according to the issue here constructive-io/libpg-query-node#22Running
yarn add --dev @ts-safeql/eslint-plugin libpg-querythrows the following errorsTo Reproduce
You can try this installation on this repo
A computer running windows OS is needed to reproduce this error
cloneprojectcdinto projectcd libpg-query-installation-errorinstallSafeQLExpected behaviour
Install SafeQL on a windows computer without an issue
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.