microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.92k stars 595 forks source link

[api-extractor] symbol has a ts.SyntaxKind.SourceFile declaration which is not (yet?) supported by API Extractor You have encountered a software defect. #1738

Open hasanayan opened 4 years ago

hasanayan commented 4 years ago

My project depends on types from @types/geojson and when I use them, api-extractor gives me following error:

Error: Internal Error: The ""/Users/hasanayan/source/@fireflyon/map/node_modules/@types/geojson/index"" symbol has a ts.SyntaxKind.SourceFile declaration which is not (yet?) supported by API Extractor You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

ninok commented 4 years ago

I'm getting the same in this repository https://github.com/heremaps/harp.gl

Error: Internal Error: The ""/home/kettlitz/development/harp.gl/node_modules/three/src/Three"" symbol has a ts.SyntaxKind.SourceFile declaration which is not (yet?) supported by API Extractor
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
octogonz commented 4 years ago

I'm getting the same in this repository https://github.com/heremaps/harp.gl

Error: Internal Error: The ""/home/kettlitz/development/harp.gl/node_modules/three/src/Three"" symbol has a ts.SyntaxKind.SourceFile declaration which is not (yet?) supported by API Extractor
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

@ninok I'm not able to repro this problem. Could you share a branch that shows how you invoke API Extractor? It seems that all the build outputs go into a centralized dist folder at the root of your repo, but I don't see any .d.ts files in that folder.

octogonz commented 4 years ago

My project depends on types from @types/geojson and when I use them, api-extractor gives me following error:

Error: Internal Error: The ""/Users/hasanayan/source/@fireflyon/map/node_modules/@types/geojson/index"" symbol has a ts.SyntaxKind.SourceFile declaration which is not (yet?)

@HasanAyan Similarly, could you provide a branch that repros this error? Otherwise there's not much to go on. (Note that api-extractor.json's mainEntryPointFilePath must point to a .d.ts file, not a .ts source file. See https://api-extractor.com/pages/setup/invoking/ for details.)

ninok commented 4 years ago

@octogonz Here is the PR for the branch I created: https://github.com/heremaps/harp.gl/pull/1354 As you can see, it is working for some modules but not for e.g. @here/harp-mapview. The PR is a bit outdated. I will rebase it tomorrow and provide more details.

octogonz commented 4 years ago

@ninok Some build instructions would also be useful. For your branch I tried:

yarn install
yarn build
yarn run api-extractor

But I got this error:

Error: Error parsing C:\GitR\harp.gl\@here\harp-geoutils\api-extractor.json:
The "mainEntryPointFilePath" path does not exist: C:\GitR\harp.gl\@here\harp-geoutils\index.d.ts

Looking at your root-level api-extractor.json file, I see this:

"mainEntryPointFilePath": "<packageName>/index.d.ts",

The file harp-geoutils/index.ts exists, but harp-geoutils/index.d.ts was not created.

It is NOT recommended to put a .d.ts output in the same folder as the .ts input file, because the TypeScript compiler engine has an IntelliSense feature that considers source code, so its analyzer will prefer to read the input .ts file. Whereas API Extractor by design only processes .d.ts output files. (API Extractor explicitly filters the .ts files from the compiler's module resolver, but it might not work perfectly.) The recommended practice is to configure tsconfig.json so that .d.ts files are written to a separate output folder such as dist or lib.

ninok commented 4 years ago

Hi @octogonz, I was replying on my phone yesterday, but now I'm on a proper PC :-)

the build of the module is missing (yarn build only builds some examples in our setup)

yarn install
yarn workspace @here/harp-geoutils build
yarn workspace @here/harp-geoutils api-extractor run

As mentioned, this will work, but following module will not work an produce the error:

yarn
yarn workspace @here/harp-mapview build
yarn workspace @here/harp-mapview api-extractor run

One intersting thing to mention: Both of these modules have a peer dependency to three.js but somehow the first one is working whereas the second one is not.

Regarding out-of-source builds: We have this in our backlog but it had no high priority until now and api-extractor can also handle it (I remember there was an issue some time ago that was fixed).

octogonz commented 4 years ago

@ninok this project is using API Extractor 7.7.8. We recently fixed an important bug that affected how global variables get analyzed. Could you try upgrading to 7.7.13? The error goes away for me when I do that.

The global variables usage is typically unintentional. What happens is some NPM package "helpfully" provides global variables alongside proper ES6 exports. Then if your source file forgets to import that API, it accidentally makes a reference to the global variable. (The react package is the most common source of trouble.) For API Extractor's .d.ts rollups, a mixture of imports/globals is sloppy and creates problems for the type analysis.

Using this command line:

api-extractor --debug run --diagnostics

...now shows these diagnostics:

Ignoring reference to global variable "Array" in C:/GitR/harp.gl/@here/harp-mapview/lib/AnimatedExtrusionHandler.d.ts:85:20
Found metadata in C:\GitR\harp.gl\@here\harp-geoutils\tsdoc-metadata.json
Found metadata in C:\GitR\harp.gl\@here\harp-datasource-protocol\tsdoc-metadata.json
Ignoring reference to global variable "HTMLCanvasElement" in C:/GitR/harp.gl/@here/harp-mapview/lib/MapView.d.ts:748:19
Ignoring reference to global variable "Promise" in C:/GitR/harp.gl/@here/harp-mapview/lib/MapView.d.ts:949:44
Ignoring reference to global variable "THREE" in C:/GitR/harp.gl/@here/harp-mapview/lib/text/ViewState.d.ts:8:18
Ignoring reference to global variable "Float32Array" in C:/GitR/harp.gl/@here/harp-mapview/lib/DisplacementMap.d.ts:5:13
Ignoring reference to global variable "ImageData" in C:/GitR/harp.gl/@here/harp-mapview/lib/image/Image.d.ts:8:17
Ignoring reference to global variable "ImageBitmap" in C:/GitR/harp.gl/@here/harp-mapview/lib/image/Image.d.ts:8:29
Ignoring reference to global variable "ArrayBufferLike" in C:/GitR/harp.gl/@here/harp-mapview/lib/Tile.d.ts:106:15
Ignoring reference to global variable "Map" in C:/GitR/harp.gl/@here/harp-mapview/lib/VisibleTileSet.d.ts:90:20
Ignoring reference to global variable "IterableIterator" in C:/GitR/harp.gl/@here/harp-mapview/lib/geometry/TileGeometryManager.d.ts:91:30
Ignoring reference to global variable "ArrayBuffer" in C:/GitR/harp.gl/@here/harp-mapview/lib/ConcurrentWorkerSet.d.ts:157:105
Ignoring reference to global variable "HTMLElement" in C:/GitR/harp.gl/@here/harp-mapview/lib/copyrights/CopyrightElementHandler.d.ts:23:38
Ignoring reference to global variable "AbortSignal" in C:/GitR/harp.gl/@here/harp-mapview/lib/ThemeLoader.d.ts:38:14
Ignoring reference to global variable "URL" in C:/GitR/harp.gl/@here/harp-mapview/lib/WorkerBasedTiler.d.ts:41:43
Ignoring reference to global variable "Worker" in C:/GitR/harp.gl/@here/harp-mapview/lib/workers/WorkerLoader.d.ts:66:70

This can help you find the missing import statements.

octogonz commented 4 years ago

@HasanAyan if you're still interested in this issue, could you also retry using API Extractor 7.7.13?

octogonz commented 4 years ago

@ninok @HasanAyan Are you still having this problem? Without additional information, we cannot investigate and will close this issue.

sedghi commented 1 year ago

@octogonz My api-extractor is working locally (here), but at our CircleCI we are getting error of

Using configuration from ./api-extractor.json
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
lerna ERR! yarn run api-check stderr:

Error: Error parsing /home/circleci/repo/packages/tools/api-extractor.json:
The "mainEntryPointFilePath" path does not exist: /home/circleci/repo/packages/tools/dist/cjs/index.d.ts
    at Function.prepare (/home/circleci/repo/node_modules/@microsoft/api-extractor/lib/api/ExtractorConfig.js:549:19)
    at RunAction.onExecute (/home/circleci/repo/node_modules/@microsoft/api-extractor/lib/cli/RunAction.js:123:65)
    at RunAction._execute (/home/circleci/repo/node_modules/@rushstack/ts-command-line/lib/providers/CommandLineAction.js:55:21)
    at ApiExtractorCommandLine.onExecute (/home/circleci/repo/node_modules/@rushstack/ts-command-line/lib/providers/CommandLineParser.js:199:39)
    at ApiExtractorCommandLine.onExecute (/home/circleci/repo/node_modules/@microsoft/api-extractor/lib/cli/ApiExtractorCommandLine.js:59:22)
    at ApiExtractorCommandLine.executeWithoutErrorHandling (/home/circleci/repo/node_modules/@rushstack/ts-command-line/lib/providers/CommandLineParser.js:164:25)
    at ApiExtractorCommandLine.execute (/home/circleci/repo/node_modules/@rushstack/ts-command-line/lib/providers/CommandLineParser.js:100:24)
    at Object.<anonymous> (/home/circleci/repo/node_modules/@microsoft/api-extractor/lib/start.js:34:8)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
error Command failed with exit code 1.
lerna ERR! yarn run api-check exited 1 in '@cornerstonejs/tools'
error Command failed with exit code 1

Any insight on this?