Closed goodbbai closed 8 months ago
IIRC Next.js is a framework to write client-side React-based web applications. re2
is a binary extension for Node written in C++. It will not work in a browser.
I am not sure why someone needs re2
on a client, but there are several offerings that use wasm
. For example:
I didn't try them so it is not an endorsement. But they can work on a client.
I'm not sure but is that a reason that Next.js can't resolve re2.node? I have known that the main feature of Next.js 13 is SSR and I put the 'require' into the server side, however, it's not worked as I said.
the reason I try to use that module is started to get metadata like a title and a publisher of a certain link. Almost every module to do that like metascraper and browserless(with cheerio) requires url-regex-safe package, and it uses re2.
I started to use the full file name since https://github.com/uhop/node-re2/releases/tag/1.18.2
Please try it and let me know if it helps or not.
IIRC Next.js is a framework to write client-side React-based web applications.
re2
is a binary extension for Node written in C++. It will not work in a browser.I am not sure why someone needs
re2
on a client, but there are several offerings that usewasm
. For example:I didn't try them so it is not an endorsement. But they can work on a client.
Next.js is both client and server side. The backend is serverless Node.js.
I started to use the full file name since
1.18.2
(release)Please try it and let me know if it helps or not.
Doesn't seem to work on 1.20.1.
you can try to use https://re2js.leopard.in.ua/ - it is pure JS ported lib, so will work in browser and node.js env, but performance is worse, than have node-re2
and browser will need load good amount of JS code
OK, I tried using your original example with minor modifications:
$ npx create-next-app@latest --ts test-re
✔ Would you like to use ESLint? … No / Yes
✔ Would you like to use Tailwind CSS? … No / Yes
✔ Would you like to use `src/` directory? … No / Yes
✔ Would you like to use App Router? (recommended) … No / Yes
✔ Would you like to customize the default import alias (@/*)? … No / Yes
Creating a new Next.js app in /Users/eugene/Open/test-re.
Using npm.
Initializing project with template: app-tw
Installing dependencies:
- react
- react-dom
- next
Installing devDependencies:
- typescript
- @types/node
- @types/react
- @types/react-dom
- autoprefixer
- postcss
- tailwindcss
- eslint
- eslint-config-next
added 333 packages, and audited 334 packages in 3s
116 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Initialized a git repository.
Success! Created test-re at /Users/eugene/Open/test-re
✔ $ cd test-re/
✔ test-re [main L|✔] $ npm i --save re2
added 101 packages, and audited 435 packages in 2m
130 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Then I created a file index.js
:
const RE2 = require('re2')
const sample= 'abbcdefabh';
const re1 = new RE2('ab*', 'g');
console.log(re1.test(sample));
Then I executed it:
$ node index.js
true
As you can see it WFM. What did I do wrong? Can you repeat what I did?
Closing for inactivity. I hope it was resolved.
When I install re2 with next.js and try to run the code, it saids
Module not found: Can't resolve './build/Release/re2'
at that path, there exists re2.node If I run test scripts without next.js, it works perfectly.The way I install it is here.
$ npx create-next-app@latest --ts test-re
$ npm i re2
my code is here.
I tried it on my intel mac and silicon mac, but the result is the same.