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

[BUG]: Types not correct #46

@filipjakov

Description

@filipjakov

Describe the bug

In order to have typings from next.config, i use @ts-check at the top of the file.

I use next-safe in the following manner:

const nextSafe = require('next-safe');
const secureHeaders = nextSafe({
	isDev: process.env.NODE_ENV !== 'production',
	contentSecurityPolicy: false, // Will be dynamically set in the app
});

and get the following type error on the nextSafe call (but works in runtime since its the suggested way of usage):

(alias) module "next-safe"
import nextSafe
This expression is not callable.
  Type 'typeof import("next-safe")' has no call signatures.

The types suggest that this is possible:

const { nextSafe } = require('next-safe');

but this fails in runtime/build attempt.

Also, in order to have a dynamic CSP (depending on environment + current page), i use this package in _app.tsx and have the same problem.

Steps To Reproduce

  1. Create new Next.js app
  2. Add @ts-check in next.config.js or use csp in a .tsx component
  3. Setup next-safe in a recommended way
  4. Start app
  5. See error

Version

v3.x.x

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

needs: triageWaiting for a contributor to triagetype: bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions