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

Trivially extending a config file changes ts-node behavior #724

Closed
samuela opened this issue Nov 5, 2018 · 6 comments
Closed

Trivially extending a config file changes ts-node behavior #724

samuela opened this issue Nov 5, 2018 · 6 comments

Comments

@samuela
Copy link

samuela commented Nov 5, 2018

I'm on yarn 1.10.1, tslint@5.11.0, typescript@3.1.6, and @types/node@10.12.2.

./tsconfig-base.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,                      /* Generates corresponding '.d.ts' file. */
    "declarationMap": true,                   /* Generates a sourcemap for each corresponding '.d.ts' file. */
    "sourceMap": true,                        /* Generates corresponding '.map' file. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "noUnusedLocals": true,                   /* Report errors on unused locals. */
    "noUnusedParameters": true,               /* Report errors on unused parameters. */
    "noImplicitReturns": true,                /* Report error when not all code paths in function return a value. */
    "noFallthroughCasesInSwitch": true,       /* Report errors for fallthrough cases in switch statement. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}

./poop/tsconfig.json:

{
  "extends": "../tsconfig-base.json",
}

./poop/index.ts:

import { spawn } from "child_process";
spawn("ls");

Now from the ./poop/ directory:

bobthebuilder [master !x?] -> yarn ts-node --project ../tsconfig-base.json index.ts
yarn run v1.10.1
$ /Users/skainswo/dev/kumo/bobthebuilder/node_modules/.bin/ts-node --project ../tsconfig-base.json index.ts

/Users/skainswo/dev/kumo/bobthebuilder/node_modules/ts-node/src/index.ts:261
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
index.ts(1,23): error TS2307: Cannot find module 'child_process'.

    at createTSError (/Users/skainswo/dev/kumo/bobthebuilder/node_modules/ts-node/src/index.ts:261:12)
    at getOutput (/Users/skainswo/dev/kumo/bobthebuilder/node_modules/ts-node/src/index.ts:367:40)
    at Object.compile (/Users/skainswo/dev/kumo/bobthebuilder/node_modules/ts-node/src/index.ts:558:11)
    at Module.m._compile (/Users/skainswo/dev/kumo/bobthebuilder/node_modules/ts-node/src/index.ts:439:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/skainswo/dev/kumo/bobthebuilder/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.




bobthebuilder [master !x?] -> yarn ts-node --project tsconfig.json index.ts
yarn run v1.10.1
$ /Users/skainswo/dev/kumo/bobthebuilder/node_modules/.bin/ts-node --project tsconfig.json index.ts
✨  Done in 1.23s.

Why does the extended config work but the base one does not?

@blakeembrey
Copy link
Member

Can you verify with TypeScript directly? I suspect it’s related to resolving your node modules type directory which is expected if the types are in your current working directory and not the parent directory.

@samuela
Copy link
Author

samuela commented Nov 5, 2018

Not exactly sure what you mean by "verify with TypeScript directly". But I was able to build both versions with tsc as expected.

@blakeembrey
Copy link
Member

blakeembrey commented Nov 5, 2018

And where is your node modules directory?

Edit: the one with @types.

@blakeembrey
Copy link
Member

Can you also supply the commands you used to verify tsc? That’ll help me understand what’s different.

@samuela
Copy link
Author

samuela commented Nov 6, 2018

My node_modules with @types is in ./poop/. Correction from earlier: yarn tsc index.ts runs without an issue, but I haven't bothered getting yarn tsc --project ../tsconfig-base.json to work. It fails with other errors because it tries to build a whole bunch of other crap. (And error TS5042: Option 'project' cannot be mixed with source files on a command line. makes that harder.)

@blakeembrey
Copy link
Member

@samuela Based on this, I think it's the expected behavior. TypeScript resolves your node_modules/@types and in the example where it's in a parent directory, they can't be found. It is not based on cwd.

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

2 participants