Can't I use `lnurl` npm library in Nextjs14?

23 Views Asked by At

In the first Nextjs14 boiler project you start, use the

npm i lnurl

After installation,

API, just by importing 'lnurl', the following error occurs.

Import trace for requested module:
./node_modules/lnurl/lib/subprotocols/channelRequest.js
./node_modules/lnurl/lib/subprotocols/index.js
./node_modules/lnurl/lib/Server.js
./node_modules/lnurl/index.js
./src/app/api/auth/route.ts
 ⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
 ⨯ ./node_modules/lnurl/lib/subprotocols/channelRequest.js
Error: 
  × Cannot use a reserved word as a shorthand property
    ╭─[/Users/mac9/project/side-p/lnurl-test/node_modules/lnurl/lib/subprotocols/channelRequest.js:41:1]
 41 │   action: function(secret, params) {
 42 │           return Promise.resolve().then(() => {
 43 │                   assert.ok(this.ln, 'Cannot execute subprotocol ("channelRequest:action"): Lightning Backend missing');
 44 │                   let { remoteid, localAmt, pushAmt, private } = params;
    ·                                       ───────
 45 │                   assert.ok(remoteid, new HttpError('Missing required parameter: "remoteid"', 400));
 46 │                   assert.ok(typeof private !== 'undefined', new HttpError('Missing required parameter: "private"', 400));
 47 │                   private = parseInt(private) === 1;
    ╰────

  × Expression expected
    ╭─[/Users/mac9/project/side-p/lnurl-test/node_modules/lnurl/lib/subprotocols/channelRequest.js:43:1]
 43 │                   assert.ok(this.ln, 'Cannot execute subprotocol ("channelRequest:action"): Lightning Backend missing');
 44 │                   let { remoteid, localAmt, pushAmt, private } = params;
 45 │                   assert.ok(remoteid, new HttpError('Missing required parameter: "remoteid"', 400));
 46 │                   assert.ok(typeof private !== 'undefined', new HttpError('Missing required parameter: "private"', 400));
    ·                     ───────
 47 │                   private = parseInt(private) === 1;
 48 │                   return this.executeHook('channelRequest:action', secret, params).then(() => {
 49 │                           // Tell the LN backend to open a new channel.
    ╰────

  × Expected ',', got 'private'
    ╭─[/Users/mac9/project/side-p/lnurl-test/node_modules/lnurl/lib/subprotocols/channelRequest.js:43:1]
 43 │                   assert.ok(this.ln, 'Cannot execute subprotocol ("channelRequest:action"): Lightning Backend missing');
 44 │                   let { remoteid, localAmt, pushAmt, private } = params;
 45 │                   assert.ok(remoteid, new HttpError('Missing required parameter: "remoteid"', 400));
 46 │                   assert.ok(typeof private !== 'undefined', new HttpError('Missing required parameter: "private"', 400));
    ·                     ───────
 47 │                   private = parseInt(private) === 1;
 48 │                   return this.executeHook('channelRequest:action', secret, params).then(() => {
 49 │                           // Tell the LN backend to open a new channel.
    ╰────

Caused by:
    Syntax Error

Import trace for requested module:
./node_modules/lnurl/lib/subprotocols/channelRequest.js
./node_modules/lnurl/lib/subprotocols/index.js
./node_modules/lnurl/lib/Server.js
./node_modules/lnurl/index.js
./src/app/api/auth/route.ts
 ⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload

For reference, it works fine on the demo site Nextjs13 below https://github.com/jowo-io/lnurl-next-auth-demo

I think that lnurl cannot be used in Nextjs.

Just following sentence is failed in Nextjs14

import lnurl from 'lnurl'
1

There are 1 best solutions below

0
keating On

I found a workaround.

Write your api in page router not app rounter

Not,
/app/api/blabla~

But,
/pages/api/blabla~

Just, it works^^