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

Add @prisma/prisma-fmt-wasm to CLI and output dependency version in -v, use instead of Formatter Engine binary #12496

Closed
janpio opened this issue Mar 23, 2022 · 12 comments · Fixed by #14760
Assignees
Labels
kind/tech A technical change. team/schema Issue for team Schema. tech/typescript Issue for tech TypeScript. topic: cli topic: prisma format CLI: prisma format topic: prisma version CLI: prisma version or -v topic: wasm
Milestone

Comments

@janpio
Copy link
Member

janpio commented Mar 23, 2022

@prisma/prisma-fmt-wasm exists and can replace the Formatter Engine binary usage in Prisma CLI already.

  1. Add @prisma/prisma-fmt-wasm as dependency (requires CI changes)
  2. Output dependency package version in -v output of Prisma CLI
  3. Replace the format (and others) call of the Formatter Engine binary with a call to the Wasm module (in a separate PR)
  4. Test CLI Engine Crash Reporting along the way to make sure it also works properly with the Wasm module
  5. Profit 🚢
@janpio janpio added topic: cli topic: prisma version CLI: prisma version or -v topic: prisma format CLI: prisma format kind/tech A technical change. team/schema Issue for team Schema. topic: wasm labels Mar 23, 2022
@janpio janpio added the tech/typescript Issue for tech TypeScript. label Mar 23, 2022
@jkomyno
Copy link
Contributor

jkomyno commented Jun 17, 2022

Note: currently, installing @prisma/prisma-fmt-wasm in prisma CLI would fail because of these lines in prisma_fmt_build.js:

//                                     .---> this isn't compatible with a monorepo
//                                     |
//                                 ^^^^^^^^
const path = require('path').join(__dirname, 'prisma_fmt_build_bg.wasm');
const bytes = require('fs').readFileSync(path);

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
wasm = wasmInstance.exports;
module.exports.__wasm = wasm;

The error I get at runtime is:

node:internal/fs/utils:345
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/Users/jkomyno/work/prisma/prisma/packages/cli/build/prisma_fmt_build_bg.wasm'
    at Object.openSync (node:fs:591:3)
    at Object.readFileSync (node:fs:459:35)
    at ../../node_modules/.pnpm/@prisma+prisma-fmt-wasm@3.16.0-24.e7e033759b8d20a2a51df5d48adb60b11c6ee4fc/node_modules/@prisma/prisma-fmt-wasm/src/prisma_fmt_build.js (/Users/jkomyno/work/prisma/prisma/packages/cli/build/index.js:58593:31)
    at __require (/Users/jkomyno/work/prisma/prisma/packages/cli/build/index.js:13:50)
    at Object.<anonymous> (/Users/jkomyno/work/prisma/prisma/packages/cli/build/index.js:96233:38)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/jkomyno/work/prisma/prisma/packages/cli/build/prisma_fmt_build_bg.wasm'
}

Node.js v18.3.0

prisma_fmt_build_bg.wasm is indeed installed into another folder: node_modules/.pnpm/@prisma+prisma-fmt-wasm@3.16.0-23.5a802ae8a39d1977852fc20e30a13566e06671cd/node_modules/@prisma/prisma-fmt-wasm/src/prisma_fmt_build_bg.wasm

@jkomyno
Copy link
Contributor

jkomyno commented Jun 17, 2022

About extracting the version of @prisma/prisma-fmt-wasm to display in prisma --version, let's remind ourselves about this issue: prisma/prisma-engines#3302

@janpio
Copy link
Member Author

janpio commented Jun 18, 2022

Note: currently, installing @prisma/prisma-fmt-wasm in prisma CLI would fail because of these lines in prisma_fmt_build.js:

Something to work on with @tomhoule.

About extracting the version of @prisma/prisma-fmt-wasm to display in prisma --version, let's remind ourselves about this issue: prisma/prisma-engines#3302

We can either implement that, or maybe use the Npm package version as an adequate replacement if that has enough information.

@tomhoule
Copy link
Contributor

tomhoule commented Jun 20, 2022

Note: currently, installing @prisma/prisma-fmt-wasm in prisma CLI would fail because of these lines in prisma_fmt_build.js:

This part I don't understand, I don't see what is wrong.

edit to add details: this is generated code (from wasm-bindgen), so changing is possible but not very practical.

@tomhoule
Copy link
Contributor

For the version, we can implement something easily, if that's what we want. The package.json approach might be better, I don't know how JS projects do it usually.

@janpio
Copy link
Member Author

janpio commented Jun 20, 2022

The issue here asks for the dependency version, so the issue @jkomyno linked to is technically not relevant unless there is a good reason not to do it that way.

@jkomyno
Copy link
Contributor

jkomyno commented Jun 21, 2022

@Jolg42 suggests that we might fix the path issue following a similar approach to https://github.com/prisma/prisma/blob/main/helpers/compile/plugins/replaceWithPlugin.ts#L44

I will try to add it to the plugins option of the applyCjsDefaults function in build.ts

@0gust1
Copy link

0gust1 commented Oct 18, 2022

We have the same kind of error as @jkomyno posted, when trying to run prisma migrate deploy on our target server.

node: 16.14.2
prisma: 4.4.0
env: Azure AppService ("classic" zip deploy)

Error: ENOENT: no such file or directory, open '/home/site/wwwroot/node_modules/.bin/prisma_fmt_build_bg.wasm'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at ../../node_modules/.pnpm/@prisma+prisma-fmt-wasm@4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6/node_modules/@prisma/prisma-fmt-wasm/src/prisma_fmt_build.js (/home/site/wwwroot/node_modules/.bin/prisma:12337:31)
    at __require (/home/site/wwwroot/node_modules/.bin/prisma:14:50)
    at Object.<anonymous> (/home/site/wwwroot/node_modules/.bin/prisma:86202:38)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    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:77:12) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/site/wwwroot/node_modules/.bin/prisma_fmt_build_bg.wasm'
}

In node_modules/@prisma/engines we have the correct engines (prisma-fmt-debian-openssl-1.1.x in our case), but it keep searching for a wasm module, at the wrong place (node_modules/.bin/prisma_fmt_build_bg.wasm).
Everything works fine in a local development context.

@jkomyno
Copy link
Contributor

jkomyno commented Oct 19, 2022

@0gust1 would you please report here what's your prisma version full output? Even though we're still shipping the formatter engine (prisma-fmt-debian-openssl-1.1.x), we've been using a WebAssembly module for prisma format for a few releases now. It'd be also awesome if you could provide more information about your project structure.
Is it a standalone project or a monorepo? Would you please have a minimally reproducible project we could look at to better understand/reproduce the issue?

By the way, I'm tracking this potential Wasm bundling problem here.

@0gust1
Copy link

0gust1 commented Oct 19, 2022

@jkomyno Hi 👋 . Thanks for the follow-up! I'll open an issue (it was on my today's TODO, after my yesterday post on #15859) and/or post on #15881. Expect some news in the next 6 hours.

Very quickly (those elements – and others – will be in the issue):
It's a standalone project; I suspect that the azure deployment could "do things" to the node_modules folder; I still can't completely rule out a problem on our own workflow. Reproductibility won't be easy (as it will need an Azure account/subscription), but I'll try.

@jkomyno
Copy link
Contributor

jkomyno commented Oct 19, 2022

@0gust1 that's great, thanks for the quick response! Please report that information directly in #15881, so we can keep track of the potential issue in a single place and keep things nice and tidy ☺️

@looppin
Copy link

looppin commented Mar 7, 2023

i am using Azure app services and i solved this problem as bellow;

  • update npm version npm install npm@latest -g
  • install again prisma with npm npm i prisma

note: make sure you are in the main folder (like /home/site/wwwroot).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/tech A technical change. team/schema Issue for team Schema. tech/typescript Issue for tech TypeScript. topic: cli topic: prisma format CLI: prisma format topic: prisma version CLI: prisma version or -v topic: wasm
Projects
None yet
6 participants