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

No input files are detected with TS 4.4 (was: .tsx support?) #12

Closed
wizzard0 opened this issue Nov 6, 2021 · 9 comments
Closed

No input files are detected with TS 4.4 (was: .tsx support?) #12

wizzard0 opened this issue Nov 6, 2021 · 9 comments

Comments

@wizzard0
Copy link

wizzard0 commented Nov 6, 2021

Expected Behavior:

  • .ts files get weaved

Observed Behavior:

  • No .ts files get weaved unless force included in litscript.json
  • UnhandledPromiseRejectionWarning: Error: Translator not registered for file: index.tsx when force-included

Steps to reproduce:

  • create empty directory
  • run npm init -y
  • add index.tsx file
  • add litsconfig.json file
  • add files: ["**.tsx"] to litsconfig.json
  • run npm i --D [email protected]
  • run npm i --D litscript
  • run lits, observe error

Works fine with TS 4.3.5

@wizzard0
Copy link
Author

wizzard0 commented Nov 6, 2021

update: am i right that by default registerTranslator is not called for anything other than .md or .css by default, and there is no way to invoke it? oops.

@johtela
Copy link
Owner

johtela commented Nov 6, 2021

Typescript files are treated differently from other supported formats, such as .md and .css. They are collected by the TypeScript compiler into a Program object and passed to litscript here.

TypeScript compiler requires a tsconfig.json file, which contains the included and excluded source folders. Typically the file has these settings:

    "include": ["src"],
    "exclude": ["node_modules"]

So, can you check that you have a tsconfig.json file that it includes the source directory where your .tsx (and .ts) files are?

That being said... I haven't used React myself, so I haven't tested how .tsx files behave. So, there might be other issues with them as well.

@wizzard0
Copy link
Author

wizzard0 commented Nov 6, 2021

yes, I have tsconfig.json too; it doesn't have an "include" field but adding it specifying default "include": ["**"] explicitly (my .ts files are in the root folder) doesn't help i.e. nothing gets included apart from README.md, whether it's .ts or .tsx

@wizzard0
Copy link
Author

wizzard0 commented Nov 6, 2021

Here's the entire tsconfig.json (non-default options only), in case it helps. I'm using TS 4.4.4

{
  "compilerOptions": {
    "target": "es2020",                                     /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "jsx": "react",                                /* Specify what JSX code is generated. */
    "module": "commonjs",                                /* Specify what module code is generated. */
    "outDir": "./rendered",                                   /* Specify an output folder for all emitted files. */
    "inlineSourceMap": true,                          /* Include sourcemap files inside the emitted JavaScript. */
    "inlineSources": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */
    "isolatedModules": true,                          /* Ensure that each file can be safely transpiled without relying on other imports. */
    "allowSyntheticDefaultImports": true,             /* Allow 'import x from y' when a module doesn't have a default export. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": true,                                 /* Skip type checking all .d.ts files. */
    "include": ["**"],
    "exclude": ["node_modules","jspm_packages"]
  },
  "include": ["**"], /* both toplevel and inside compilerOptions don't seem to have any effect on both TS and lits */
  "exclude": ["node_modules","jspm_packages"]
}

@wizzard0
Copy link
Author

wizzard0 commented Nov 6, 2021

Well, I added console.log(cl) after the let cl = ts.parseJsonConfigFileContent(configFile.config, parseConfigHost, opts.baseDir) line, and that object contains the error no inputs were specified

But if I run tsc directly, then files are indeed compiled, both to the dest dir, or to the single file if I specify "outFile" instead

@wizzard0
Copy link
Author

wizzard0 commented Nov 6, 2021

Ah i see. Downgrading typescript to 4.3 (npm i [email protected]) works.
But then my code doesn't typecheck anymore :\ (I heavily rely on the 4.4-only Control Flow Analysis of Aliased Conditions feature to make type checks more readable).

Fixed the issue title and description to match

@wizzard0 wizzard0 changed the title .tsx support? No input files are detected with TS 4.4 (was: .tsx support?) Nov 6, 2021
@johtela
Copy link
Owner

johtela commented Nov 7, 2021

Thanks for looking into this. I think the culprit is this change in TypeScript 4.4. As you noticed parseJsonConfigFileContent does not like the default baseDir (which is the current directory .) anymore.

A workaround is to explicitly set the baseDir to absolute path of your project directory in litsconfig.json. Something like this:

{
    "baseDir": "C:/Users/tommi/source/repos/litscript",
    "updateToc": true,
    ...

I will make a change to the next version of LiTScript that expands the baseDir to an absolute path before calling parseJsonConfigFileContent. That should fix the issue.

@andrewbranch
Copy link

andrewbranch commented Nov 11, 2021

Duplicate of #46577—I’m in the process of reverting all related changes back to their 4.3 state. Thanks everyone!

@andrewbranch
Copy link

Lol, that’s why GitHub wouldn’t link to that issue—I don’t even know what repo I’m in. Sorry all, it’s been quite a week prepping for TS 4.5, in which this issue should be fixed! 😅 I was so confused as to why I couldn’t label this issue a duplicate 😂

@johtela johtela closed this as completed Feb 18, 2022
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