Import from local file to next.config.js

Viewed 567

This may be applicable to node modules in general, but I am experiencing this with next.config.js in my Next.js application.

When I try to import from a local file in next.config.js like so:

const {I18N} = require('./utils/constants/i18n')

During build it throws an error:

Error: Cannot find module './utils/constants/i18n'

The path is correct. Also, npm intellisense pluging in VS Code editor suggests/auto-completes this exact path.

Any idea how to fix this?

1 Answers

You should use JSON to use the require method

Related