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

TS shows an error with express middleware #341

Closed
delphinus opened this issue Jun 13, 2019 · 3 comments · Fixed by #348
Closed

TS shows an error with express middleware #341

delphinus opened this issue Jun 13, 2019 · 3 comments · Fixed by #348
Assignees
Labels
api: logging Issues related to the googleapis/nodejs-logging-winston API. type: question Request for information or clarification. Not an issue.

Comments

@delphinus
Copy link

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS: macOS Mojave 10.14.5
  • Node.js version: 12.4.0
  • npm version: 6.9.0
  • @google-cloud/logging-winston version: 1.0.0

Steps to reproduce

  • I created a minimal repo to reproduce: https://github.com/delphinus/logging-winston-test

    1. Write minimal TS to use express middleware.
    import express from 'express'
    import * as lw from '@google-cloud/logging-winston'
    
    const app = express()
    
    ;(async () => {
      const { mw } = await lw.express.middleware()
      app.use(mw)
      app.get('/', (req, res) => {
        (req as any).log.info('this is log')
        res.status(200).send('Hello, World!').end()
      })
    })()
    1. compile
    npx tsc
    1. Shows an error
    node_modules/@google-cloud/logging-winston/build/src/index.d.ts:85:45 - error TS2507: Type 'typeof TransportStream' is not a constructor function type.
    
    85 export declare class LoggingWinston extends TransportStream {
                                                   ~~~~~~~~~~~~~~~
    
    
    Found 1 error.
@ofrobots
Copy link
Contributor

I believe this is ultimately a problem with TypeScript's esModuleInterop flag. There is no value of the flag we can set on our side that makes all our users happy :(.

Is it possible for you to not use esModuleInterop?

Related: googleapis/nodejs-logging-bunyan#241

@DominicKramer DominicKramer added the type: question Request for information or clarification. Not an issue. label Jun 13, 2019
@JustinBeckwith
Copy link
Contributor

FWIW - we've usually found the problem arrises when downstream dependencies are using esModuleInterop. Where does TransportStream come from? Is it possible the types for Winston are using esModuleInterop?

@delphinus
Copy link
Author

@ofrobots I see it fixes this by using esModuleInterop: false & CommonJS style require.

delphinus/logging-winston-test#1

I will fix my code base to use this way -- esModuleInterop: false, but is this a usual way on Google side? I have been using esModuleInterop: true all the time after TS introduced this option in 2.7.

ES module style (import express from 'express') is more TS-way than CommonJS style (import express = require('express')) and MS highly recommends that. Is it difficult to convert this repo to use it?

ofrobots added a commit to ofrobots/nodejs-logging-winston that referenced this issue Jun 17, 2019
`transport-stream` uses a CommonJS style export. The way we were
importing was giving errors to using `esModuleInterop`. Use the special
syntax for this style of modules.

Fixes: googleapis#341
Fixes: googleapis#342
ofrobots added a commit that referenced this issue Jun 17, 2019
`transport-stream` uses a CommonJS style export. The way we were
importing was giving errors to using `esModuleInterop`. Use the special
syntax for this style of modules.

Fixes: #341
Fixes: #342
@google-cloud-label-sync google-cloud-label-sync bot added the api: logging Issues related to the googleapis/nodejs-logging-winston API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging-winston API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants