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

[api-extractor] Support import statements inside namespaces (new in TypeScript 3.9) #1914

Open
1 task done
chudongvip opened this issue Jun 4, 2020 · 14 comments
Open
1 task done
Labels
ae-ts-version Tracks API Extractor issues involving support for recent TypeScript versions enhancement The issue is asking for a new feature or design change help wanted If you're looking to contribute, this issue is a good place to start! repro confirmed The issue comments included repro instructions, and the maintainers reproduced the problem

Comments

@chudongvip
Copy link

chudongvip commented Jun 4, 2020

  • Bug

error message:

Error: Internal Error: getResolvedModule() could not resolve module name "../enums/local-invitation-failure-reason"
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

env:

  • windows 10
  • node 12.6.0
  • api-extractor 7.8.10

code

local-invitation-failure-reason.ts

export enum LocalInvitationFailureReason {
    TEXT:  "TEXT"
}

remote-invitation-failure-reason.ts

export enum RemoteInvitationFailureReason {
    ACCEPT_FAILURE:  "ACCEPT_FAILURE"
}

rtm.ts

import { RemoteInvitationFailureReason } from "./remote-invitation-failure-reason"
import { LocalInvitationFailureReason } from "./local-invitation-failure-reason"
let defaultVal:any;

export module ArRTM {
  export const RemoteInvitationFailureReason:RemoteInvitationFailureReason = defaultVal;
  export const LocalInvitationFailureReason :LocalInvitationFailureReason = defaultVal;
  export const VERSION                      :string = "";
}

main.ts

export { RTM } from './rtm';

command line

  1. tsc
  2. api-extractor run
  3. the shell client throw an exception
@octogonz
Copy link
Collaborator

octogonz commented Jun 4, 2020

I am not able to repro this.

In order to get the code to compile, I had to change the enum definitions to use = like this:

export enum LocalInvitationFailureReason {
    TEXT:  "TEXT"
}

and I needed to rename ArRTM to RTM. But otherwise API Extractor processed it without any trouble.

Could you share a complete branch that repros this problem? Thanks!

@octogonz octogonz added the needs more info We can't proceed because we need a better repro or an answer to a question label Jun 4, 2020
@chudongvip
Copy link
Author

I am not able to repro this.

In order to get the code to compile, I had to change the enum definitions to use = like this:

export enum LocalInvitationFailureReason {
    TEXT:  "TEXT"
}

and I needed to rename ArRTM to RTM. But otherwise API Extractor processed it without any trouble.

Could you share a complete branch that repros this problem? Thanks!

thanks for reply, sure, i will create private repository and then i will invite you as a collaborator.

@octogonz
Copy link
Collaborator

octogonz commented Jun 5, 2020

I saw that you created an api-extractor-demo repo. Let me know when it's set up and you have some repro steps. Thanks!

@chudongvip
Copy link
Author

I saw that you created an api-extractor-demo repo. Let me know when it's set up and you have some repro steps. Thanks!

ok. you can follow the setp:

  1. npm install
  2. npm run dev or npm run build
  3. api-extractor run

and then you can saw the error show on your shell client

@chudongvip
Copy link
Author

I saw that you created an api-extractor-demo repo. Let me know when it's set up and you have some repro steps. Thanks!

Hey bro, how it is going.

@octogonz
Copy link
Collaborator

octogonz commented Jun 8, 2020

ok. you can follow the setp:

1. npm install
2. npm run dev or npm run build
3. api-extractor run

I don't see any scripts in your package.json for npm run dev or npm run build. I am looking at the master branch.

@octogonz
Copy link
Collaborator

octogonz commented Jun 8, 2020

I tried running tsc manually and then api-extractor run, but I didn't encounter any error:

api-extractor 7.8.10  - https://api-extractor.com/

Using configuration from api-extractor-demo\config\api-extractor.json

Warning: The API report file is missing. Please copy the file "temp/ar-rtm-sdk.api.md" to "etc/ar-rtm-sdk.api.md", or perform a local build (which does this automatically). See the Git repo documentation for more info.
Warning: src/classes/localInvitation.ts:11:5 - (tsdoc-undefined-tag) The TSDoc tag "@hidden" is not defined in this configuration
Warning: src/classes/localInvitation.ts:17:1 - (ae-missing-release-tag) "LocalInvitation" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Warning: src/classes/localInvitation.ts:23:6 - (tsdoc-undefined-tag) The TSDoc tag "@hidden" is not defined in this configuration
Warning: src/modules/anyrtc-rtm.ts:21:4 - (tsdoc-undefined-tag) The TSDoc tag "@hidden" is not defined in this configuration
Warning: src/modules/anyrtc-rtm.ts:41:1 - (ae-missing-release-tag) "ArRTM" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)

API Extractor completed with warnings

Please provide more detailed repro instructions. Thanks!

@chudongvip
Copy link
Author

I tried running tsc manually and then api-extractor run, but I didn't encounter any error:

api-extractor 7.8.10  - https://api-extractor.com/

Using configuration from api-extractor-demo\config\api-extractor.json

Warning: The API report file is missing. Please copy the file "temp/ar-rtm-sdk.api.md" to "etc/ar-rtm-sdk.api.md", or perform a local build (which does this automatically). See the Git repo documentation for more info.
Warning: src/classes/localInvitation.ts:11:5 - (tsdoc-undefined-tag) The TSDoc tag "@hidden" is not defined in this configuration
Warning: src/classes/localInvitation.ts:17:1 - (ae-missing-release-tag) "LocalInvitation" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Warning: src/classes/localInvitation.ts:23:6 - (tsdoc-undefined-tag) The TSDoc tag "@hidden" is not defined in this configuration
Warning: src/modules/anyrtc-rtm.ts:21:4 - (tsdoc-undefined-tag) The TSDoc tag "@hidden" is not defined in this configuration
Warning: src/modules/anyrtc-rtm.ts:41:1 - (ae-missing-release-tag) "ArRTM" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)

API Extractor completed with warnings

Please provide more detailed repro instructions. Thanks!

ooh, sorry,the correct procedure is:

  • webpack
  • api-extractor run

@chudongvip
Copy link
Author

PS E:\workbench\anyrtc\anyRTC-SDK\anyRTC-SDK-TS> cd .\ArRtmWebSDK\
PS E:\workbench\anyrtc\anyRTC-SDK\anyRTC-SDK-TS\ArRtmWebSDK> webpack
i 「atl」: Using [email protected] from typescript
i 「atl」: Using tsconfig.json from E:/workbench/anyrtc/anyRTC-SDK/anyRTC-SDK-TS/ArRtmWebSDK/tsconfig.json
i 「atl」: Checking started in a separate process...
i 「atl」: Time: 213ms
Hash: 97e5263ea550c849d7a9
Version: webpack 4.43.0
Time: 2333ms
Built at: 2020-06-09 10:20:31
                              Asset       Size  Chunks             Chunk Names
..\lib\classes\localInvitation.d.ts  419 bytes          [emitted]
                   ..\lib\main.d.ts  125 bytes          [emitted]
     ..\lib\modules\anyrtc-rtm.d.ts   1.98 KiB          [emitted]
                           ArRTM.js   2.64 KiB       0  [emitted]  main
Entrypoint main = ArRTM.js
[0] ./src/main.ts 902 bytes {0} [built]
[1] ./src/modules/anyrtc-rtm.ts 1.54 KiB {0} [built]
[2] ./src/classes/localInvitation.ts 1.65 KiB {0} [built]
PS E:\workbench\anyrtc\anyRTC-SDK\anyRTC-SDK-TS\ArRtmWebSDK> api-extractor run

api-extractor 7.8.10  - https://api-extractor.com/

Using configuration from E:\workbench\anyrtc\anyRTC-SDK\anyRTC-SDK-TS\ArRtmWebSDK\config\api-extractor.json

Error: Internal Error: getResolvedModule() could not resolve module name "../enums/local-invitation-failure-reason"
You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
PS E:\workbench\anyrtc\anyRTC-SDK\anyRTC-SDK-TS\ArRtmWebSDK>

@toyobayashi
Copy link

The same problem.

Repo: https://github.com/toyobayashi/denostd/tree/dts-rollup-error

Branch: dts-rollup-error

  • windows 10 1903
  • node 12.18.0
  • typescript 3.9.5
  • api-extractor 7.8.11
> npm run prepare

> @tybys/[email protected] prepare E:\Github\denostd
> node ./scripts/index.js

Output cjs ... (tsc)
Output esm ... (tsc)
Output umd ... (rollup esm output code)
Output umd .d.ts ... (invoke api-extractor dts rollup. entry: dist/esm/std/path/mod.d.ts)

InternalError: Internal Error: getResolvedModule() could not resolve module name "./_interface"

You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
    at ExportAnalyzer._fetchSpecifierAstModule (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\ExportAnalyzer.js:536:19)
    at ExportAnalyzer._getExportOfSpecifierAstModule (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\ExportAnalyzer.js:451:41)
    at ExportAnalyzer._tryMatchImportDeclaration (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\ExportAnalyzer.js:380:29)
    at ExportAnalyzer.fetchReferencedAstEntity (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\ExportAnalyzer.js:251:45)
    at AstSymbolTable._analyzeChildTree (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\AstSymbolTable.js:282:76)
    at AstSymbolTable._analyzeChildTree (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\AstSymbolTable.js:310:18)
    at AstSymbolTable._analyzeChildTree (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\AstSymbolTable.js:310:18)
    at AstSymbolTable._analyzeChildTree (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\AstSymbolTable.js:310:18)
    at AstSymbolTable._analyzeChildTree (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\AstSymbolTable.js:310:18)
    at AstSymbolTable._analyzeChildTree (E:\Github\denostd\node_modules\@microsoft\api-extractor\lib\analyzer\AstSymbolTable.js:310:18) {
  unformattedMessage: 'getResolvedModule() could not resolve module name "./_interface"'
}

@octogonz octogonz added the repro confirmed The issue comments included repro instructions, and the maintainers reproduced the problem label Jun 11, 2020
@octogonz
Copy link
Collaborator

api-extractor-demo still doesn't repro for me, even using webpack.

But denostd does fail -- I can debug that. Thanks!

@octogonz
Copy link
Collaborator

octogonz commented Jun 11, 2020

Okay this file is the problem:

C:\GitR\denostd\dist\esm\std\path\win32.d.ts

declare namespace _win32 {
/** This module is browser compatible. */
import { FormatInputPathObject, ParsedPath } from "./_interface";  <=== ERROR
export const sep = "\\";
export const delimiter = ";";
export function resolve(...pathSegments: string[]): string;
. . .
}
export default _win32;

API Extractor uses the TypeScript 3.7 compiler (see issue #1866), which reports an error for that import statement:

TS 1147: Import declarations in a namespace cannot reference a module

Whereas you are using TypeScript 3.9.

When I move the import statement to the top of the file (in both win32.d.ts and posix.d.ts), then API Extractor completes successfully.

We need to update API Extractor to formally support TypeScript 3.9, but sheesh, this year the compiler has been introducing tons of fundamentally new syntax that is difficult to keep up with.

I'll also note that by targeting the bleeding edge compiler, you may reduce the audience who can consume your library. For some users, migrating to latest TypeScript version can involve nontrivial effort.

Could I ask you to keep your denostd repo around until we fix this? It's a pretty useful test case.

@octogonz octogonz changed the title [api-extractor] Internal Error: getResolvedModule() could not resolve module name "__/__" [api-extractor] Support import statements inside namespaces (new in TypeScript 3.9) Jun 11, 2020
@octogonz octogonz added enhancement The issue is asking for a new feature or design change help wanted If you're looking to contribute, this issue is a good place to start! and removed needs more info We can't proceed because we need a better repro or an answer to a question labels Jun 11, 2020
@toyobayashi
Copy link

Thank you to figure out what is the problem, welcome to use this repo to debug anytime. By the way now api-extractor still does not support import * as ___ from ___ for local paths yet, when can this feature complete?

@octogonz
Copy link
Collaborator

The current progress is in #1796, and that branch has been published as 7.8.2-pr1796.0 which you can use until we get the PR merged.

@octogonz octogonz added the ae-ts-version Tracks API Extractor issues involving support for recent TypeScript versions label Jul 2, 2020
@github-project-automation github-project-automation bot moved this to Needs triage in Bug Triage Feb 26, 2024
@iclanton iclanton moved this from Needs triage to AE/AD in Bug Triage Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ae-ts-version Tracks API Extractor issues involving support for recent TypeScript versions enhancement The issue is asking for a new feature or design change help wanted If you're looking to contribute, this issue is a good place to start! repro confirmed The issue comments included repro instructions, and the maintainers reproduced the problem
Projects
Status: AE/AD
Development

No branches or pull requests

3 participants