Skip to content

Typescript: ambient declaration file that declares a namespace results in build errors #7167

Closed
@andyhopp

Description

@andyhopp

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes
$ npm --version
6.9.0

Which terms did you search for in User Guide?

Typescript Declaration @types

Environment

Environment Info:

System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Binaries:
Node: 10.15.3 - /usr/local/bin/node
npm: 6.9.0 - /usr/local/bin/npm
Browsers:
Chrome: 74.0.3729.169
Firefox: 60.6.2
Safari: 12.1.1
npmPackages:
react: ^16.8.6 => 16.8.6
react-dom: ^16.8.6 => 16.8.6
react-scripts: 3.0.1 => 3.0.1
npmGlobalPackages:
create-react-app: 2.1.8

Steps to Reproduce

  1. create-react-app my-app --typescript
  2. cd my-app
  3. npm i --save-dev @types/amazon-connect-streams
  4. Create a file named src/connect-service.ts:
export class Connect {
    constructor() {
    }

    public initialize(ccpElement: HTMLElement, options: connect.InitCCPOptions) {
        connect.core.initCCP(ccpElement, options);
        console.log('CCP Initialized!');
    }
}
  1. npm i -g typescript # To demonstrate the Typescript compiler
  2. tsc --build tsconfig.json # Note no errors
  3. npm run-script build

Expected Behavior

I expected the CRA build to behave similarly to the native TS compiler.

Actual Behavior

=============
Failed to compile.

./src/connect-service.ts
  Line 6:  'connect' is not defined  no-undef

Search for the keywords to learn more about each error.


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! connect-react-example@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the connect-react-example@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Reproducible Demo

The steps above only require an NPM install of a types file and a single file to be created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions