question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid TypeScript Type (Default Export)

See original GitHub issue

PostCSS exports default type as seen in the type file:

https://github.com/postcss/postcss/blob/master/lib/postcss.d.ts

However that is certainly not the case because a code calling default exported type will not run:

import postcss from 'postcss';

        const postcssResult = await postcss([autoprefixer])
            .process(sassResult.css, postcssOptions);
TypeError: postcss_1.default is not a function

Instead, shouldn’t the TypeScript declaration use export = ?

https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require

Not to mention, calling import postcss = require('postcss'); from TypeScript will not compile anymore due to this type declaration change!


Workaround for those affected by this issue: revert back to PostCSS 7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Semigradskycommented, Oct 9, 2020

Yes, move from “commonjs .js and .mjs” to “esm .js and .cjs” should help. In this case typings will be correct.

1reaction
Semigradskycommented, Oct 8, 2020

TS doesn’t support .mjs files yet, so current typings lie. Typings should be rewritten to commonjs declare namespace ... and export = X style 😞

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript default export undefined - Stack Overflow
With current version of typescript (2.6 or below), you need to write your definition file with export assignment instead of default export:
Read more >
TypeScript errors and how to fix them
When you are importing a module with built-in TypeScript declarations and TypeScript tells you that this module does not have a default export,...
Read more >
Avoid Export Default - TypeScript Deep Dive - Gitbook
Discoverability is very poor for default exports. You cannot explore a module with intellisense to see if it has a default export or...
Read more >
Content Types - ESBuild
#The default export can be error-prone. The ES module format (i.e. ESM) have a special export called default that sometimes behaves differently than...
Read more >
How To Use Modules in TypeScript | DigitalOcean
src/vector2.ts:1:1 - error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found