rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[api-extractor] Internal Error: Cannot assign isExternal

Open npirotte opened this issue 6 years ago • 8 comments
trafficstars

api-extractor version: 7.0.17

Hi,

I am running into an error whenever I try to export a react component as part of my public api.

 throw new node_core_library_1.InternalError(`Cannot assign isExternal=${options.isExternal} for`
            ^

Error: Internal Error: Cannot assign isExternal=true for the symbol React because it was previously registered with isExternal=false

I have no idea how to deal with that, this was working fine with version 6. Could anyone give me a hint?

The only workaround I have now is to export React from my index.ts (Not something I want to do indeed)

npirotte avatar Mar 04 '19 13:03 npirotte

First found: It looks like it's working when I turn esModuleInterop to false (and remove all esModuleInterop type imports)

npirotte avatar Mar 04 '19 14:03 npirotte

Second found: It's also working with esModuleInterop, but not if I mix 2 flavors.

And by the way the esModuleInterop output something strange: import { default } from "react"

npirotte avatar Mar 04 '19 14:03 npirotte

Can you share a repro branch? We're very close to releasing AE7, so this week I'm going through and retesting various projects to find any remaining blocking bugs.

I wonder if your case is an import form that is not recognized. Yesterday I found this one:

https://github.com/Microsoft/web-build-tools/pull/1127

octogonz avatar Mar 04 '19 16:03 octogonz

Let me quickly create something (current case in on a private repo)

npirotte avatar Mar 05 '19 08:03 npirotte

https://github.com/collibra/api-extractor-example

But I was not able to reproduce the failure, maybe a combination on small things on my project, I clean up some stuffs and continue investigations.

You can still checkout the default issue here https://github.com/collibra/api-extractor-example/blob/master/temp/api-extractor-example.api.ts and here https://github.com/collibra/api-extractor-example/blob/master/dist/typings/typings.d.ts

maybe it's expected behavior, but it makes it hard for reviewer :)

npirotte avatar Mar 05 '19 09:03 npirotte

Agreed we should probably emit a better name than default. But your code is mixing together two different ways of importing React:

import React from "react";
import * as React from "react";

That's not a best practice.

BTW it is nontrivial for API Extractor to figure out these two forms refer to the same thing, so even if we fix the default name, you may still see two names like React and React_2. (Long term we'll fix that as well, but it's a cosmetic issue and thus lower priority.)

octogonz avatar Mar 05 '19 10:03 octogonz

I'm now running into this error as well: UnhandledPromiseRejectionWarning: Error: Internal Error: Cannot assign isExternal=true for the symbol React because it was previously registered with isExternal=false

I tried replacing the few places that were using import * as React from 'react' with import React from 'react', but the same error still happens.

How can I find our which file is triggering that error? I tried setting a breakpoint in apps/api-extractor/src/analyzer/AstSymbolTable.ts but couldn't make sense of the options object.

lizozom avatar Mar 03 '20 09:03 lizozom

Bump into same issue for different object in my case.

Error: [vite:dts] Internal Error: Cannot assign isExternal=false for the symbol HashObject because it was previously registered with isExternal=true 

You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
    at AstSymbolTable._fetchAstSymbol (/node_modules/@microsoft/api-extractor/lib/analyzer/AstSymbolTable.js:530:19)
    at ExportAnalyzer.fetchReferencedAstEntity (/node_modules/@microsoft/api-extractor/lib/analyzer/ExportAnalyzer.js:311:48)
    at ExportAnalyzer._tryGetExportOfAstModule (/node_modules/@microsoft/api-extractor/lib/analyzer/ExportAnalyzer.js:626:34)
    at ExportAnalyzer._getExportOfAstModule (/node_modules/@microsoft/api-extractor/lib/analyzer/ExportAnalyzer.js:599:32)
    at ExportAnalyzer._getExportOfSpecifierAstModule (/node_modules/@microsoft/api-extractor/lib/analyzer/ExportAnalyzer.js:594:32)
    at ExportAnalyzer._tryMatchImportDeclaration (/node_modules/@microsoft/api-extractor/lib/analyzer/ExportAnalyzer.js:518:29)
    at ExportAnalyzer.fetchReferencedAstEntity (/node_modules/@microsoft/api-extractor/lib/analyzer/ExportAnalyzer.js:293:45)
    at AstSymbolTable._analyzeChildTree (/node_modules/@microsoft/api-extractor/lib/analyzer/AstSymbolTable.js:332:76)
    at AstSymbolTable._analyzeChildTree (/node_modules/@microsoft/api-extractor/lib/analyzer/AstSymbolTable.js:377:18)
    at AstSymbolTable._analyzeChildTree (/node_modules/@microsoft/api-extractor/lib/analyzer/AstSymbolTable.js:377:18)

nazarhussain avatar Apr 19 '24 10:04 nazarhussain