Skip to content

[Bug]: The Typescript PR needs to be more robust in getPnpApi to work with Vite/esbuild/rollup in the browser. #4050

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

Closed
1 task
francisu opened this issue Feb 1, 2022 · 2 comments · Fixed by #5210
Labels
bug Something isn't working upholded Real issues without formal reproduction

Comments

@francisu
Copy link
Contributor

francisu commented Feb 1, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

The famous PnP microsoft/TypeScript#35206 introduces a getPnpApi() function which does a require("module") to help determine if PnP is present.

When using with https://vitejs.dev/ in the browser (yes I'm running the Typescript compiler in the browser, which works just fine with Webpack 4), the result of require("module") is a Proxy object which blows up if you touch it. This is a problem.

Here is what I have done to the patched version in typescript.js which works:

function getPnpApi(path) {
  var m;
  try {
    m = require("module");
  } catch (error) {
  }
  if (typeof m?.findPnpApi !== 'function') {
    return undefined;
  }
  var findPnpApi = m.findPnpApi;
  if (findPnpApi === undefined) {
    return undefined;
  }
  return findPnpApi("".concat(path, "/"));
}

In addition, I changed my vite.config.js to exclude module, but it's unclear that that's really necessary.

FYI - Vite uses esbuild for yarn start and Rollup for the production build.

To reproduce

Use the Typescript compiler in the browser and Vite to bundle it. Do a yarn start, and it will get an error at runtime.

Environment

System:
    OS: macOS 12.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 14.17.3 - /private/var/folders/s7/1ndbqwz50xd84b32lkmj97900000gn/T/xfs-1f0ffe89/node
    Yarn: 3.1.1 - /private/var/folders/s7/1ndbqwz50xd84b32lkmj97900000gn/T/xfs-1f0ffe89/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v14.17.3/bin/npm

Additional context

No response

@francisu francisu added the bug Something isn't working label Feb 1, 2022
@yarnbot
Copy link
Collaborator

yarnbot commented Mar 4, 2022

Hi! 👋

This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! 😃

If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! 🌟

@yarnbot yarnbot added the stale Issues that didn't get attention label Mar 4, 2022
@yarnbot yarnbot closed this as completed Mar 9, 2022
@merceyz merceyz reopened this Mar 10, 2022
@merceyz merceyz added upholded Real issues without formal reproduction and removed stale Issues that didn't get attention labels Mar 10, 2022
@sachinraja
Copy link

Ran into this issue when bundling patched TypeScript for the browser with Webpack 4 and was forced to switch to a -dev version (which yarn doesn't have a patch for). Maybe we could have an option to opt out of the patch for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upholded Real issues without formal reproduction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants