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

Dom lib required for TS to compile in Node app #2896

Closed
mikewim opened this issue Oct 13, 2021 · 5 comments · Fixed by #3890
Closed

Dom lib required for TS to compile in Node app #2896

mikewim opened this issue Oct 13, 2021 · 5 comments · Fixed by #3890
Assignees
Labels
bug This issue is a bug. investigating Issue is being investigated and/or work is in progress to resolve the issue.

Comments

@mikewim
Copy link

mikewim commented Oct 13, 2021

Describe the bug

Dom lib required by typescript in order to successfully compile node app

Your environment

SDK version number

@aws-sdk/lib-dynamodb@3.36.0

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the Node.js

v12.22.4

Steps to reproduce

  • Create a fresh TS workspace
  • Set minimal tsconfig.json and do not include "dom" in lib array
  • Install @aws-sdk/lib-dynamodb@3.36.0
  • import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; into hello world file
  • run tsc to compile project

Observed behavior

The source code fails to compile with error:
Screen Shot 2021-10-13 at 11 43 12 AM

Expected behavior

lib installed into node app should not require "dom" types to compile

Additional context

If you add "dom" to lib array in tsconfig.json, source code will compile successfully

@mikewim mikewim added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 13, 2021
@simonbuchan
Copy link
Contributor

Getting typescript isomorphic code to compile without assertions across environments generally sucks, but in the public interface looks something like:

// Declare interfaces that will get merged with the real definitions in lib.dom and @types/node
declare global {
  export interface ReadableStream {}

  export namespace NodeJS {
    export interface Readable {}
  }

  // ...
}

export type InputStream = ReadableStream | NodeJS.Stream;

Really, it's missing a typescript feature, maybe declare interface ReadableStream {} that evaluates to never if not otherwise defined?

@ajredniwja ajredniwja added investigating Issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2021
@ibqn
Copy link

ibqn commented Dec 19, 2021

I hit this error with @aws-sdk/util-dynamodb package

$ yarn build
yarn run v1.22.10
$ tsc
lambda-fns/node_modules/@aws-sdk/util-dynamodb/dist-types/ts3.4/models.d.ts:12:59 - error TS2304: Cannot find name 'Blob'.
12 export declare type NativeAttributeBinary = ArrayBuffer | Blob | Buffer | DataView | File | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
                                                             ~~~~

lambda-fns/node_modules/@aws-sdk/util-dynamodb/dist-types/ts3.4/models.d.ts:12:86 - error TS2304: Cannot find name 'File'.
12 export declare type NativeAttributeBinary = ArrayBuffer | Blob | Buffer | DataView | File | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
                                                                                        ~~~~


Found 2 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@jfirebaugh
Copy link

For discussions of how this might be fixed, see https://stackoverflow.com/questions/65848540 and microsoft/TypeScript#31894.

@thw0rted
Copy link

thw0rted commented Jan 4, 2022

Sadly I think the most common solution you'll find in the wild is people adding a triple-slash reference to DOM types, which, yes, pollutes the global namespace of anyone who includes your library with all the DOM types.

You might also be interested in following microsoft/TypeScript-DOM-lib-generator#1207 which, if implemented, could allow you to import individual types from the DOM without having them exist in global scope.

juliusfitzhugh-ccpo added a commit to dod-ccpo/atat-web-api that referenced this issue Mar 15, 2022
- Remove CORS related code
- Minor refactoring
- Updating comments

Removing 'dom' from tsconfig.json produces error during tsc build
during github action Run Tests.
- required to workaround aws/aws-sdk-js-v3#2896

Ticket: AT-7050
juliusfitzhugh-ccpo added a commit to dod-ccpo/atat-web-api that referenced this issue Mar 15, 2022
- Remove CORS related code
- Minor refactoring
- Updating comments

Removing 'dom' from tsconfig.json produces error during tsc build
during github action Run Tests.
- required to workaround aws/aws-sdk-js-v3#2896

Ticket: AT-7050
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. investigating Issue is being investigated and/or work is in progress to resolve the issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants