Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid default export type declaration #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jstasiak
Copy link

I bumped into an issue when attempting to use @markdoc/next.js 0.3.7 in a Next.js application.

next.config.js contents:

//@ts-check

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

const withMarkdoc = require('@markdoc/next.js')

/**
 * @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, }, pageExtensions: ['mdoc'], }

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

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

Attempting to build the project failed with

  ▲ Next.js 14.2.15

   Skipping linting
   Checking validity of types  .Failed to compile.

./next.config.js:25:45
Type error: This expression is not callable.
  Type 'typeof import("/lune/lune-fe/apps/docs/node_modules/@markdoc/next.js/src/index")' has no call signatures.

  23 | ]
  24 |
> 25 | module.exports = composePlugins(...plugins)(withMarkdoc()(nextConfig))
     |                                             ^
  26 |

arethetypeswrong says the 0.3.7 types are indeed wrong[1]:

Incorrect default export

The resolved types use export default where the JavaScript file
appears to use module.exports =. This will cause TypeScript under
the node16 module mode to think an extra .default property access is
required, but that will likely fail at runtime. These types should
use export = instead of export default.

[2] says that if the .js file uses "module.exports = ..." syntax the .d.ts file should say "export = ...".

With this change the Next.js project I'm working on builds successfully and arethetypeswrong is happy.

[1] https://arethetypeswrong.github.io/?p=%40markdoc%2Fnext.js%400.3.7
[2] https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/fcb426886791997e20b98225ba5ccd7f77dfc6d9/docs/problems/FalseExportDefault.md

…t export

I bumped into an issue when attempting to use @markdoc/next.js 0.3.7 in
a Next.js application.

next.config.js contents:

    //@ts-check

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

    const withMarkdoc = require('@markdoc/next.js')

    /**
     * @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,
        },
        pageExtensions: ['mdoc'],
    }

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

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

Attempting to build the project failed with

      ▲ Next.js 14.2.15

       Skipping linting
       Checking validity of types  .Failed to compile.

    ./next.config.js:25:45
    Type error: This expression is not callable.
      Type 'typeof import("/lune/lune-fe/apps/docs/node_modules/@markdoc/next.js/src/index")' has no call signatures.

      23 | ]
      24 |
    > 25 | module.exports = composePlugins(...plugins)(withMarkdoc()(nextConfig))
         |                                             ^
      26 |

arethetypeswrong says the 0.3.7 types are indeed wrong[1]:

    Incorrect default export

    The resolved types use export default where the JavaScript file
    appears to use module.exports =. This will cause TypeScript under
    the node16 module mode to think an extra .default property access is
    required, but that will likely fail at runtime. These types should
    use export = instead of export default.

[2] says that if the .js file uses "module.exports = ..." syntax the .d.ts
file should say "export = ...".

With this change the Next.js project I'm working on builds successfully and
arethetypeswrong is happy.

[1] https://arethetypeswrong.github.io/?p=%40markdoc%2Fnext.js%400.3.7
[2] https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/fcb426886791997e20b98225ba5ccd7f77dfc6d9/docs/problems/FalseExportDefault.md
Copy link

cla-assistant bot commented Oct 23, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

cla-assistant bot commented Oct 23, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jstasiak jstasiak changed the title Fix "typeof import ... has no call signatures"-causing invalid default export Fix invalid default export in the type declarations Oct 23, 2024
@jstasiak jstasiak changed the title Fix invalid default export in the type declarations Fix invalid default export type declaration Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants