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

Multi version doesn't work with tsconfig setting esModuleInterop=true #179

Closed
max-block opened this issue Oct 16, 2018 · 3 comments
Closed

Comments

@max-block
Copy link

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

I've created a new project:

maxblock@mbp tmp $ npx oclif multi mynewcli
npx: installed 439 in 22.142s

     _-----_     ╭──────────────────────────╮
    |       |    │      Time to build a     │
    |--(o)--|    │  multi-command CLI with  │
   `---------´   │  oclif! Version: 1.12.4  │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

? npm package name mynewcli
? command bin name the CLI will export mynewcli
? description bla
? author maxblock @max-block
? version 0.0.0
? license MIT
? Who is the GitHub owner of repository (https://github.com/OWNER/repo) max-block
? What is the GitHub name of repository (https://github.com/owner/REPO) mynewcli
? Select a package manager npm
? TypeScript Yes
? Use tslint (linter for TypeScript) Yes
? Use mocha (testing framework) No

Than I've updated tsconfig.json, I've added "esModuleInterop": true setting:


{
  "compilerOptions": {
    "declaration": true,
    "importHelpers": true,
    "module": "commonjs",
    "outDir": "lib",
    "rootDir": "src",
    "strict": true,
    "target": "es2017",
    "composite": true,
    "esModuleInterop": true
  },
  "include": [
    "src/**/*"
  ]
}

Than I updated hello.ts to check how it works if I import modules in esModuleInterop mode:

import fs from 'fs'
....
this.log(fs.readdirSync('/').join(' '))

But it doesn't work:

maxblock@mbp mynewcli $ bin/run hello
hello world from ./src/commands/hello.ts
TypeError: Cannot read property 'readdirSync' of undefined
    at Hello.run (~/projects/tmp/mynewcli/src/commands/hello.ts:28:17)
    at Hello._run (~/projects/tmp/mynewcli/node_modules/@oclif/command/lib/command.js:29:31)

For single cli esModuleInterop=true works fine, the problem only with multi version.

Versions:

  • oclif 1.12.4
  • macOS: 10.13.6
@jdx
Copy link
Contributor

jdx commented Oct 16, 2018

I'm pretty sure this is the underlying reason: oclif/config#44

the tsconfig isn't used by oclif at all for ts-node. Fixing it isn't trivial though.

@mfellner
Copy link

mfellner commented Nov 5, 2018

We are maintaining a CLI based on oclif in a TypeScript mono-repo. All packages have set esModuleInterop to true except for the CLI. During development we have problems with the CLI depending on the other packages' code because the import statements cannot be resolved.

Currently we have this workaround in place:

--- a/node_modules/@oclif/config/lib/ts-node.js
+++ b/node_modules/@oclif/config/lib/ts-node.js
@@ -34,6 +34,7 @@ function registerTSNode(root) {
             // cache: false,
             // typeCheck: true,
             compilerOptions: {
+                esModuleInterop: tsconfig.compilerOptions.esModuleInterop,
                 target: tsconfig.compilerOptions.target || 'es2017',
                 module: 'commonjs',
                 sourceMap: true,

@jdxcode Would it make sense to add this behaviour to oclif by default?

@jdx
Copy link
Contributor

jdx commented Nov 6, 2018

@mfellner I'd be happy with that patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants