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';
}