Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

False positive in Next.js Config file: next.config.js #583

@deadcoder0904

Description

@deadcoder0904

I have the following next.config.js:

const { createLoader } = require('simple-functional-loader')
const rehypePrism = require('@mapbox/rehype-prism')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
	enabled: process.env.ANALYZE === 'true',
})

module.exports = withBundleAnalyzer({
	pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
	experimental: {
		modern: true,
	},
	webpack: (config, options) => {
		config.module.rules.push({
			test: /\.(svg|png|jpe?g|gif|mp4)$/i,
			use: [
				{
					loader: 'file-loader',
					options: {
						publicPath: '/_next',
						name: 'static/media/[name].[hash].[ext]',
					},
				},
			],
		})

		const mdx = [
			options.defaultLoaders.babel,
			{
				loader: '@mdx-js/loader',
				options: {
					rehypePlugins: [rehypePrism],
				},
			},
		]

		config.module.rules.push({
			test: /\.mdx$/,
			oneOf: [
				{
					resourceQuery: /preview/,
					use: [
						...mdx,
						createLoader(function (src) {
							if (src.includes('<!--more-->')) {
								const [preview] = src.split('<!--more-->')
								return this.callback(null, preview)
							}

							const [preview] = src.split('<!--/excerpt-->')
							return this.callback(null, preview.replace('<!--excerpt-->', ''))
						}),
					],
				},
				{
					use: [
						...mdx,
						createLoader(function (src) {
							const content = [
								'import Blog from "@/components/Blog"',
								'export { getStaticProps } from "@/utils/blog/getStaticProps"',
								'export { getStaticPaths } from "@/utils/blog/getStaticPaths"',
								src,
								'export default (props) => <Blog meta={meta} {...props} />',
							].join('\n')
							
							if (content.includes('<!--more-->')) {
								return this.callback(null, content.split('<!--more-->').join('\n'))
							}

							return this.callback(null, content.replace(/<!--excerpt-->.*<!--\/excerpt-->/s, ''))
						}),
					],
				},
			],
		})

		return config
	},
})

It has @mdx-js/loader in it but when I use depcheck it gives me a false positive:

➜ depcheck 
Unused dependencies
* @mdx-js/runtime
* gray-matter
Unused devDependencies
* @mdx-js/loader

I think it shouldn't show @mdx-js/loader :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions