An error occurred in the nx.dev next.config.js file: The token 'export' was unexpected

How can I import another library in next.config.js in a nx.dev monorepo?

I encountered an error when running nx dev project-app:

Failed to process the project graph. Run "nx reset" to resolve this issue. Please report it if it persists. See errors below.

Failed to process the project graph. Run "nx reset" to fix this. Please report the issue if you keep encountering it.
  AggregateCreateNodesError: There was an error while processing files for the @nx/next/plugin plugin.
    - apps/project-app/next.config.js: Unexpected token 'export'

I started with an empty next.js template and created a default JavaScript library using nx.dev.

app/project-app/next.config.js

//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
const {mylib} = require('@project/mylib');

console.log(mylib())

/**
 * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = {
  nx: {
    // Set this to true if you would like to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: false,
  },
};

const plugins = [
  // Add more Next.js plugins to this list if needed.
  withNx,
];

module.exports = composePlugins(...plugins)(nextConfig);

mylib/src/index.ts

export function mylib(): string {
  return 'mylib';
}

Answer №1

let combinedPluginsConfig = mergePlugins(...plugins)(config);
module.exports = combinedPluginsConfig

Give the above code snippet a shot

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

Extracting image dimensions using JavaScript - a simple guide

Having created a test for an upcoming project, I have encountered a problem that I am struggling to resolve. Despite my efforts to search the internet for a solution, I have been unable to find one due to: My limited understanding of Javascript The code l ...

Exploring techniques for navigating through deeply nested JSON arrays

Struggling with diving deep into the third level of an API's JSON structure, I initially attempted to use a certain method without success. Encouraged to explore the Loadash library, I integrated it into my code but encountered issues. Seeking assista ...

Passing a JSON variable from PHP to JavaScript using Ajax at an inconvenient timing

On my input form, users are required to provide a link. PHP checks the validity of the link and then sends it to JavaScript via Ajax. For debugging purposes, JavaScript displays the URL in a div. The issue I'm facing is that the printed link is alway ...

Tips on maximizing efficiency in number game coding

Seeking to create a number using a specified set of 6+ inputs. For instance, aiming for the number 280 with inputs [2,4,5,10,30,50,66], the desired output format would be something like this: ((2+5) * 4 * 10). Each input number can only be used once per s ...

Tips for converting Numbers or JSON to strings while exporting data to an Excel spreadsheet in React

I have been using react-html-table-to-excel to export my table to Excel. However, I have encountered a specific issue. I am unable to convert a Number to a string in one column. When I try to cast the Number to a string using <td>{String(post.did)} ...

Tips for closing the navbar by clicking elsewhere on the page

Is there a way to modify my code in order for the navbar to close when clicking outside of it, while staying open if something inside it is clicked? $(document).ready(function() { $('.nav-btn').on('click', function() { $('.na ...

Duplicating labels with JavaScript

I need assistance with copying HTML to my clipboard. The issue I am encountering is that when I try to copy the button inside the tagHolder, it ends up copying <span style="font-family: Arial; font-size: 13.3333px; text-align: center; background-color: ...

Unexpected behavior found in certain parts of jquery due to the implementation of Ajax

Every time I try to use the ajax code on the same page or an external .js file, it seems to cause issues and prevents other parts of the code (jquery) from functioning properly. The ajax should only trigger when clicking on a specific li element with the c ...

Organizing an array of objects by sorting them according to their internal data and grouping them together

Looking to organize this array of objects in a hierarchical structure: var channels = [{ cid: 5, pid: 10 }, { cid: 10, pid: 0 }, { cid: 20, pid: 5 }, { cid: 15, pid: 10 }]; In this case, cid represents channel Id and pid r ...

Next and Nest servers enable the handling of SSR and client requests separately using distinct frontend and backend servers

Currently, I have a NestJS backend that holds the data, including user information, and a NextJS frontend. In my setup, Next redirects all requests to an /api route to Nest, where authentication and data serving take place. Authentication is done by Nest u ...

Try implementing a dynamic id to modify the background when hovering over the menu in the DAWN THEME

I have successfully created an editable section in the customizer where you can upload desktop and mobile images, as well as modify the menu. My current dilemma is how to associate these background images with each "Details-id" and have them change when a ...

What is the best way to capture GotError [HTTPError]: When the response code 404 (Not Found) occurs in a nodejs

If the URL provided is incorrect and the Got module raises a HTTPError, how can I properly catch the error? Using try-catch does not seem to be effective in this situation. const got = require('got'); got(`https://www.wrongurl.com`) ...

Tips on showcasing the elements within a div container using flexbox

Seeking advice on positioning items/cards using flexbox in my initial react app. The issue lies with the div within my card component where applying display: flex; turns every card into a block (column-like) structure, flexing only the content within each ...

Would you like to learn how to set an auto-play video as the background in a webpage section, similar to the one found on http://www8.hp.com/in/en/home.html?

I was browsing the HP-India website and noticed they have a cool autoplay video in the background of a section below the header. I would love to recreate something similar on my own website. Any tips on how to achieve this? ...

The Javascript navigation bar is not displaying properly on mobile devices as it should

After customizing the responsive navbar tutorial from W3Schools using CSS and JS, I encountered an issue. I wanted to include a logo and a web page title before the navbar, which worked perfectly when the webpage was maximized. However, when I resized the ...

The pointerTap event is triggered 7 times when a PIXI.Sprite is clicked within a React component

Using the PIXI library in my React application to render animations, the stage is created with @inlet/react-pixi and gsap is used for tweening. During the initial launch of the app, a clickable sprite is created and an event listener "pointerTap" is added ...

How can I extend the execution limit for a Server Action in NextJS / Vercel?

Running a Server Action in NextJS14 on Vercel, I've noticed in the logs that the function is timing out: Execution Duration / Limit. 15.01s / 15s (timed out) The OpenAI API call may be causing the delay. Is there a way to extend the time limit for ...

Use Backbone.js to dynamically insert partial views based on specific routes, similar to how ng-view works in AngularJS

After gaining experience with AngularJs, I am now looking to dive into Backbone.js. However, I am struggling to understand how this library handles routes and partial views/templates "injection". In Angular, we can easily set up static components like th ...

Steps for disabling a specific input type in HTML

I have created a web application with CRUD functionality. My current objective is to differentiate the Add and Edit functions. Here's what I mean: When a user invokes the Add function, they are required to provide an ID, while the Edit function should ...

Unable to transfer array elements to a function within PhantomJS

I am facing a challenge in extracting the source code from multiple webpages simultaneously. The links are stored in an array from a source text file. While I am able to successfully loop through the array and display the links, I encounter an issue when p ...