Is it possible to integrate the `lnurl` npm library with Nextjs14?

When starting the first boilerplate project in Nextjs14, remember to include the following command:

npm i lnurl

However, after installation and attempting to use the API by importing 'lnurl', an error occurs as shown below:

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

If you encounter issues with lnurl in Nextjs14, it is worth noting that it works smoothly on the demo site for Nextjs13 available at https://github.com/jowo-io/lnurl-next-auth-demo.

Based on my experience, using 'import lnurl from 'lnurl'' has failed in Nextjs14.

Please note that lnurl may not be compatible with Nextjs environment.

Answer №1

I have discovered a solution.

Make sure to write your API in page router instead of app rounter

Don't use,
/app/api/blabla~

Instead, use,
/pages/api/blabla~

Just like that, it works perfectly!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to navigate from a button in NextJS to another page that I have built within the same application?

As I work on developing a website for a pet rescue charity using Next.js, I am facing an issue with getting my button or link to function correctly. Every time I try to navigate to another page within my Next.js app, I encounter a 404 error stating "This p ...

Text that doesn't appear overwhelming in a Framer Motion text reveal animation

As a newcomer to Framer Motion, I recently attempted to create a Stagger Text effect and a Text Reveal Animation for my portfolio based on various articles. However, despite trying multiple examples, I have encountered an issue where the animation occurs s ...

Tips on employing useState within useEffect?

Attempting to refactor my component from react.component to hooks has been a bit challenging. I am struggling to properly utilize the state variable offsetTop. It seems like the value is not being set when needed. In my first attempt: const [offsetTop, se ...

What is the best way to create a function that can securely search for a URL containing parameters while ensuring type safety?

I am working on a NextJS/React application. We have a large object containing internal URLs, each with a createPath function that looks similar to this: const URLS = { dashboard: { createPath: ({ accountNumber }: { accountNumber: string }) => ...

The NextAuth file imported with the EmailProvider is currently not being utilized

Having an issue with implementing nextauth for authentication. I have imported EmailProvider from nextauth/providers but when I try to use it in the Nextauth providers object, it does not recognize the EmailProvider that I've imported. Here is the co ...

After successfully sending a GET request to the API, the Next.js 13.4.3 website still does not reflect new posts added on the hosting platform

I am currently using Next.js version 13.4.3 in my app directory to create a blog site. However, I am facing an issue. When I run npm run build locally on my computer and then start with npm run start, the new posts are displayed normally after adding them ...

Using NextJS with Storybook: The Issue with Optional Chaining

https://i.stack.imgur.com/lY2F1.png rehype-ignore - index.js contains the following code snippet: import { visit } from 'unist-util-visit'; const rehypeIgnore = (options = {}) => { const { openDelimiter = 'rehype:ignore:start', ...

Error message: Next.js - Unable to access properties of an undefined object (user)

I am currently utilizing Next.js and Next-auth in my current project. Within this project, I am working on creating a Sidebar component that will display a list of items specific to each user. To achieve this, I am using the useSession hook to retrieve t ...

Mastering the Autoplay feature in Embla carousel for your next.js project

I successfully implemented an Embla carousel in my next/js project, closely resembling this example. To make it functional, I included use client at the beginning of the file. Now, I'm attempting to integrate Autoplay functionality using this library. ...

Guide on mapping dynamic pages in Next13.3 for efficient sitemap creation

I am currently following the recommended method for generating a sitemap in Next13.3+ by using a sitemap.js file located in the app folder. Below is an example of the code I have implemented (please note that these are just placeholder URLs and should be r ...

Is it acceptable to use JavaScript files in the pages directory in NEXTJS13, or is it strongly advised to only use TypeScript files in the most recent version?

In the previous iterations of nextJS, there were JavaScript files in the app directory; however, in the most recent version, TypeScript files have taken their place. Is it still possible to begin development using JavaScript? I am working on creating an a ...

Is it secure to store the access token within the NextAuth session?

Utilizing a custom API built with Node.js and Express.js, I have implemented nextAuth to authenticate users in my Next.js application. Upon a successful login, the date is stored in the nextAuth session and can be accessed using the useSession hook. To acc ...

Why isn't my Enum functioning properly to display the colored background?

Why isn't the Background Color showing up when I pass in the BGColor Prop dynamically in my next.js + Tailwind app? I have tried passing in the prop for my component, but the color is not appearing. <Title title='This is HOME' descripti ...

The string "ikm" must consist of at least one byte

https://example.com/errors#error1 "xyz" should have a minimum length of one character { message: '"xyz" should have a minimum length of 1', stack: 'TypeError: "xyz" should have a minimum length of 1\n' ...

Tips for utilizing the next link href based on a specific condition

The following code snippet is causing me some trouble: <a onClick={() => { if (fortype === "user") { if (rd.track !== null) { router.push({ pathname: `/tracks/${rd.track._id}`, query: { fr ...

The combination of useEffect and Client component has the power to greatly

As a newcomer to React development, I've encountered a blocking error in my code that isn't being detected by Visual Studio Code. Here's the code snippet for my NavBar component: import React, { useState, useEffect } from "react"; import Ima ...

Updating Next.js to React 18 is causing issues with my API calls that are being made using next-auth

Let me share an unusual situation with you. I am utilizing Next.js along with the Next-auth package for managing authentication. For this particular admin area, Server-Side rendering is not necessary. To authenticate users, I have devised a HOC to wrap a ...

How can I resolve the issue if a specific file within a package cannot be located using NPM?

What are the steps to troubleshoot when a file inside a package cannot be located? Error: Module not found: Can't resolve 'images/loading-icon.gif' ./node_modules/react-pdf-highlighter/node_modules/pdfjs-dist/web/pdf_viewer.css I'm cur ...

What is the best way to incorporate SWRs pagination for effectively managing pagination within a URL structure?

In an attempt to address the lack of pagination handling on the backend in this NextJS application, I proposed passing it as query parameters in the URL, like localhost:3000/patients?page=. My initial approach was close: import React, { useEffect } from & ...

The data type 'string' cannot be assigned to the type 'SystemStyleObject | undefined' in the context of Next.js and Chakra UI

I am currently working on a project that involves Next.js, TypeScript, and Chakra UI. While configuring Button themes in the button.ts file, I encountered an error related to the baseStyle object for properties like borderRadius, color, and border: Type & ...