Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

require substitution is not working #414

Closed
fdutey opened this issue Aug 7, 2021 · 6 comments
Closed

require substitution is not working #414

fdutey opened this issue Aug 7, 2021 · 6 comments

Comments

@fdutey
Copy link

fdutey commented Aug 7, 2021

Im actually wondering if i'm missing something obvious on how to use this plugin. No matter if I add it to my package.json or not, it doesn't change anything.

I'm running into the problem where require is being spit into my browser (using relay with vitejs) and the browser doesn't know what to do with that. I tried every possible solution (babel-commonjs, write my own vite plugins...) but nothing is solving the issue.

I saw that you have, in master branch, some transformers to address this specific problem (even though it's been said in this discussion facebook/relay#3354 that it should be part of relay compiler and not this plugin).
I cloned the repo, built the plugin (with a lot of efforts :>) and yet, nothing happens. It's like the plugin is not here.

If I put some throw in the code, in root functions, it's still working.
And yet, there's nothing in the documentation saying that there's any specific configuration to do to activate this plugin (nor in relay compiler's code to declare such plugins).

Thanks in advance.

@n1ru4l
Copy link
Member

n1ru4l commented Aug 7, 2021

I think master changes have not been released yet. See #405 and #407

@fdutey
Copy link
Author

fdutey commented Aug 8, 2021

Ok so I got progress

  1. First problem was linked to yarn pnp, not the compiler itself. I'm very sorry about that, I should have thought about it before opening the ticket.
  2. I start playing arround with my local copy of ts compiler and realized that loadCompilerOptions function was silentely failing at parsing my tsconfig (even though my project was running). That led having an empty compilerOptions all along the compiling process and replaceRequire was false in formatContent options.

Could be awesome if

  1. we could have a feedback when failing to load compiler options (I have no error in other context :/)
  2. we could manually override replaceRequire somehow (looks like the compiler is not sending any option to the plugin, that's pretty sad)

My problem is solved anyway so thanks for your answer and god bless this code addition 6 days ago :D

@n1ru4l
Copy link
Member

n1ru4l commented Aug 8, 2021

@fdutey Feel free to send a PR that enhances the experience!

@fdutey
Copy link
Author

fdutey commented Aug 8, 2021

For feedback, that shouldn't be a problem.

For the second one though, I'm very unfamiliar with relay compiler so sending options from it to the plugin if it doesn't allow it already (need to check) is gonna be impossible. I was actually thinking about a rc file but im afraid that it won't be welcomed by the community since it's not already existing (and it will be "yet another another rc").
Any thoughts on that?

@holmesal
Copy link
Contributor

I also came across an issue where this plugin was (very quietly) failing to parse our tsconfig properly. In our case, the error was due to relay-compiler-language-typescript's invocation of ts.parseJsonConfigFileContent with a relative basePath, which led to an error being returned stating that no inputs were found. See #470

+1 for logging these errors to the console! All of our other TS tooling was working properly, so it wasn't obvious that I needed to start dropping logs in loadCompilerOptions and looking for errors parsing our typescript config. 😅

@n1ru4l
Copy link
Member

n1ru4l commented Oct 27, 2021

CLosing this as it seems to be fixed

@n1ru4l n1ru4l closed this as completed Oct 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants