rtsao Github contribution chart
rtsao Github Stats
rtsao Most Used Languages

Activity

22 Sep 2022

Rtsao

Codemod that convert CommonJS(require/exports) to ES Modules(import/export) for JavaScript/TypeScript

Forked On 22 Sep 2022 at 12:31:51

Rtsao

chore: remove unused images from docs [ci skip]

sponsor images are not remotely loaded from a service

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix: module graph ensureEntryFromUrl based on id (#9759)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

refactor: use server.ssrTransform (#9769)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

test: refactor config load (#9762)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix(html): move importmap before module scripts (#9392)

Co-authored-by: 翠 / green green@sapphi.red

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

chore: output tsconfck debug log (#9768)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

docs: fix typos (#9776)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

chore(deps): update dependency postcss-modules to v5 (#9779)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

feat: support object style hooks (#9634)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

chore(deps): update all non-major dependencies (#9778)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

chore: remove custom vitepress config (#9785)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix: Skip inlining Git LFS placeholders (fix #9714) (#9795)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

refactor: migrate from vue/compiler-dom to parse5 (#9678)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix: close socket when client error handled (#9816)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix(plugin-legacy): prevent global process.env.NODE_ENV mutation (#9741)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix: injectQuery break relative path (#9760)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

fix: completeSystemWrapPlugin captures function () (fixes #9807) (#9821)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

feat: relax dep browser externals as warning (#9837)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

release: v3.1.0-beta.0

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

feat(client): use debug channel on hot updates (#8855)

Pushed On 19 Sep 2022 at 05:54:19

Rtsao

chore: remove unused images from docs [ci skip]

sponsor images are not remotely loaded from a service

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix: module graph ensureEntryFromUrl based on id (#9759)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

refactor: use server.ssrTransform (#9769)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

test: refactor config load (#9762)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix(html): move importmap before module scripts (#9392)

Co-authored-by: 翠 / green green@sapphi.red

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

chore: output tsconfck debug log (#9768)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

docs: fix typos (#9776)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

chore(deps): update dependency postcss-modules to v5 (#9779)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

feat: support object style hooks (#9634)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

chore(deps): update all non-major dependencies (#9778)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

chore: remove custom vitepress config (#9785)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix: Skip inlining Git LFS placeholders (fix #9714) (#9795)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

refactor: migrate from vue/compiler-dom to parse5 (#9678)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix: close socket when client error handled (#9816)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix(plugin-legacy): prevent global process.env.NODE_ENV mutation (#9741)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix: injectQuery break relative path (#9760)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

fix: completeSystemWrapPlugin captures function () (fixes #9807) (#9821)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

feat: relax dep browser externals as warning (#9837)

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

release: v3.1.0-beta.0

Pushed On 19 Sep 2022 at 05:40:08

Rtsao

feat(client): use debug channel on hot updates (#8855)

Pushed On 19 Sep 2022 at 05:40:08
Merge
Rtsao Wants To Merge vitejs/vite

Rtsao

feat: transform jsx with esbuild instead of babel

Description

Resolves https://github.com/vitejs/vite/issues/9429

Additional context

Development JSX transforms

esbuild supports dev-only JSX transforms (i.e. jsxDev: true) but this only works when using the automatic runtime. To preserve this functionality with the classic runtime, @babel/plugin-transform-react-jsx-self and @babel/plugin-transform-react-jsx-source will still be used in development when using the classic runtime.


What is the purpose of this pull request?

  • [ ] Bug fix
  • [x] New Feature
  • [ ] Documentation update
  • [ ] Other

Before submitting the PR, please make sure you do the following

  • [x] Read the Contributing Guidelines.
  • [x] Read the Pull Request Guidelines and follow the Commit Convention.
  • [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • [x] Ideally, include relevant tests that fail without this PR but pass with it.

Forked On 19 Sep 2022 at 05:36:36

Rtsao

I've updated this PR to use the new JSX side effects option in esbuild
On 19 Sep 2022 at 05:36:36
Merge

Rtsao

feat: transform jsx with esbuild instead of babel

Description

Resolves https://github.com/vitejs/vite/issues/9429

Additional context

Development JSX transforms

esbuild supports dev-only JSX transforms (i.e. jsxDev: true) but this only works when using the automatic runtime. To preserve this functionality with the classic runtime, @babel/plugin-transform-react-jsx-self and @babel/plugin-transform-react-jsx-source will still be used in development when using the classic runtime.


What is the purpose of this pull request?

  • [ ] Bug fix
  • [x] New Feature
  • [ ] Documentation update
  • [ ] Other

Before submitting the PR, please make sure you do the following

  • [x] Read the Contributing Guidelines.
  • [x] Read the Pull Request Guidelines and follow the Commit Convention.
  • [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • [x] Ideally, include relevant tests that fail without this PR but pass with it.

Merged On 19 Sep 2022 at 05:36:37

Rtsao

Commented On 19 Sep 2022 at 05:36:37

Rtsao

fix: legacy no emit worker (#9500)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix(ssr): rename objectPattern dynamic key (fixes #9585) (#9609)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix: json HMR (fixes #9521) (#9610)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix(optimizer): ignore EACCES errors while scanner (fixes #8916) (#9509)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix(plugin-react): wrong substitution causes React is not defined (#9386)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix: use browser field if it is not likely UMD or CJS (fixes #9445) (#9459)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

feat: show warning on 431 response (#9324)

Co-authored-by: Bjorn Lu bjornlu.dev@gmail.com

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix: don't count class declarations as react fast refresh boundry (fixes #3675) (#8887)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix(legacy): skip esbuild transform for systemjs (#9635)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

chore: narrow down rollup version (#9637)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

release: v3.0.6

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

release: plugin-vue@3.0.2

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

release: plugin-react@2.0.1

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

release: plugin-legacy@2.0.1

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

release: create-vite@3.0.1

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

refactor(legacy): remove code for Vite 2 (#9640)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

chore: remove vitest global options (#9620)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

fix(config): don't use file url for external files with cjs output (#9642)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

chore: fix typo in error message (#9645)

Pushed On 19 Sep 2022 at 05:35:16

Rtsao

release: v3.0.7

Pushed On 19 Sep 2022 at 05:35:16
Pull Request

Rtsao

Add JSX side effects option

Created On 14 Sep 2022 at 02:27:08
Create Branch
Rtsao In rtsao/esbuild Create Branchjsx-pure-option

Rtsao

An extremely fast JavaScript bundler and minifier

On 14 Sep 2022 at 02:24:51
Create Branch
Rtsao In rtsao/esbuild Create Branchjsx-pure

Rtsao

An extremely fast JavaScript bundler and minifier

On 14 Sep 2022 at 02:15:30
Issue Comment

Rtsao

SSR external packages with entries break when not hoisted

Describe the bug

When marking a package as an SSR external, it should also mark any sub-entry points of the same module as external. While it's not explicitly documented, this is what I believe the intended behaviour is from reading prior issues and the source code.

e.g.

// vite.config.js
export default {
  ssr: {
    external: ['lodash']
  }
} 
// should be external
import lodash from 'lodash';

// should also be external
import omit from 'lodash/omit'; 

Unfortunately, this feature (sub-entry externals) doesn't work when the package being marked as external isn't a top-level package inside node_modules. Package managers that use hoisting likely get around this issue, however pnpm and other package manages that don't hoist seem to break this feature.

In practice, this means that the behaviour of ssr.external is different depending on whether packages are top-level dependencies or not. Due to the way ssr.noExternal works, using ssr.external on nested deps is essential in more complex scenarios.

After debugging the source code, this issue seems to occur because import specifiers that exactly match the external are treated differently to package matches. Package matches have to go through a node resolve check in order to be externalised, however the resolve check runs from the project root, therefore always failing for non top-level packages.

Excerpt from the source code:

// copied from https://github.com/vitejs/vite/blob/9ac5075825212e5f4f3b262225ff4a3e46b8e8d1/packages/vite/src/node/ssr/ssrExternal.ts#L158

  // Returns true if it is configured as external, false if it is filtered
  // by noExternal and undefined if it isn't affected by the explicit config
  return (id: string) => {
    const { ssr } = config
    if (ssr) {
      if (
        // If this id is defined as external, force it as external
        // Note that individual package entries are allowed in ssr.external
        ssr.external?.includes(id)
      ) { 
        return true // <-- straight external match doesn't require more validation
      }
      const pkgName = getNpmPackageName(id)
      if (!pkgName) {
        return isExternalizable(id)
      }
      if (
        // A package name in ssr.external externalizes every
        // externalizable package entry
        ssr.external?.includes(pkgName)
      ) {
        return isExternalizable(id, true) // <-- package entry external match requires resolve check for some reason?
      }
      if (typeof noExternal === 'boolean') {
        return !noExternal
      }
      if (noExternalFilter && !noExternalFilter(pkgName)) {
        return false
      }
    }
    return isExternalizable(id)
  } 

I have validated that changing the package entry check above to immediately return true rather than going through isExternalizable fixes this issue. Unless this breaks other Vite behaviour, I'd suggest that would be the easiest fix and I'd be happy to submit a PR doing this.

Alternatively, the node resolve algorithm inside isExternalizable could resolve from the dependent package location rather than the project root.

I think this issue is related to but not the same as #9710.

Reproduction

https://github.com/mattcompiles/vite-ssr-external-repro

System Info

System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 609.50 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.volta/tools/image/node/16.15.0/bin/node
    npm: 8.5.5 - ~/.volta/tools/image/node/16.15.0/bin/npm
    pnpm: 7.9.5
  Browsers:
    Chrome: 104.0.5112.101
    Firefox: 104.0.1
    Safari: 15.6
  npmPackages:
    @vitejs/plugin-react: ^2.0.0 => 2.0.0
    vite: ^3.0.9 => 3.0.9 

Used Package Manager

pnpm

Logs

> ssr-external-repro@0.0.0 test /Users/mjones/projects/ssr-external-repro
> node test

node:internal/process/esm_loader:94
    internalBinding('errors').triggerUncaughtException(
                              ^

ReferenceError: require is not defined
    at eval (/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/mapValues.js:3:36)
    at instantiateModule (file:///Users/mjones/projects/ssr-external-repro/node_modules/.pnpm/vite@3.0.9/node_modules/vite/dist/node/chunks/dep-0fc8e132.js:50548:15) 

Validations

Forked On 13 Sep 2022 at 12:39:34

Rtsao

Alternatively, the node resolve algorithm inside isExternalizable could resolve from the dependent package location rather than the project root.

This is the fix implemented in https://github.com/vitejs/vite/pull/9763

Commented On 13 Sep 2022 at 12:39:34

Rtsao

started

Started On 10 Sep 2022 at 05:25:41

Rtsao

Ensure PnP ESM loader is used when available

The logic to load the PnP ESM loader need to be reversed, as previously it would skip the loader if it's present on the filesystem

Merged On 08 Sep 2022 at 11:33:20

Rtsao

Commented On 08 Sep 2022 at 11:33:20
Started

Rtsao

started

Started On 31 Aug 2022 at 08:53:03
Issue Comment

Rtsao

fix(ssr): ensure sup-dependencies are correctly externalized if not resolvable from root

Description

Fixes https://github.com/vitejs/vite/issues/9710

The externalizer logic unconditionally attempts to resolve encountered dependencies from the project root. This works fine with hoisted node_modules installations, but does not work with more strict installation schemes where only explicit dependencies are only resolvable (such as pnpm or Yarn PnP). In this case, the externalizer is unable to resolve the sub-dependency from the root, and as a result it is not externalized for SSR.

For example, suppose we have the following dependency graph: app -> dep-a -> dep-b

With npm, dep-b is resolvable from app (the root) because it is hoisted:

code
├── node_modules
│   ├── dep-a
│   └── dep-b
└── app 

However, pnpm and PnP ensure strictness where dep-b cannot be resolved from app (and must be resolved from dep-a):

code
└── app
    └── node_modules
        └── dep-a
            └── node_modules
                └── dep-b 

In this case, dep-b fails to be externalized for SSR (resulting in errors if dep-b is CJS)

This PR fixes the issue by passing along the importer and resolving from the importer, thereby allowing it to be resolved correctly.

Additional context

The externalization logic is memoized so resolution for a given package name only happens once. However, now resolution depends on two parameters: the package name and the importing path.

But taking into consideration the importing path would largely defeat the point of the cache as misses would be frequent.

I'm not super familiar with the intended logic of externalization, but I suppose a given package is OK to externalize as long as it was resolvable at some point. That being said, I think there probably needs to be more thinking about edge cases here, but I would need some help understanding the original context of this code.


What is the purpose of this pull request?

  • [x] Bug fix
  • [ ] New Feature
  • [ ] Documentation update
  • [ ] Other

Before submitting the PR, please make sure you do the following

  • [x] Read the Contributing Guidelines.
  • [x] Read the Pull Request Guidelines and follow the Commit Convention.
  • [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • [x] Ideally, include relevant tests that fail without this PR but pass with it.

Forked On 22 Aug 2022 at 02:31:28

Rtsao

Hmm, it seems strange to me that it would be expected behavior to crash SSR in the common scenario of a pnpm or Yarn monorepo with CJS dependencies and default configuration.

IMHO there shouldn’t need to be configuration to prevent a crash in this case. CJS packages are the overwhelming majority of npm dependencies. Manually adding and maintaining dozens (if not hundreds) of exceptions for every CJS dependency seems like an unreasonable burden.

Commented On 22 Aug 2022 at 02:31:28

Rtsao

Add early returns to caveats

Pushed On 19 Aug 2022 at 09:37:25
Issue Comment

Rtsao

CommonJS dependencies crash SSR server

Describe the bug

CommonJS dependencies encountered during SSR can crash the server (e.g. ReferenceError: module is not defined or ReferenceError: require is not defined, depending on which is first) if workspaces are used in some capacity.

I have identified two specific scenarios where this will occur:

  1. The CJS dependency is a workspace (i.e. appcjs-workspace)
  2. The CJS dependency is a sub-dependency of a workspace dependency (i.e. appother-workspacecjs-npm-dependency) AND pnpm or Yarn PnP is used.

While possibly confusing, the first scenario is arguably intentional behavior because workspaces are typically implemented with symlinks and this logic indicates that symlinked packages should never be externalized: https://github.com/vitejs/vite/blob/c6870f37161f479b4306826e1e4d8e42ed01d6a8/packages/vite/src/node/plugins/resolve.ts#L656-L659

However, the second scenario is almost certainly a bug.

Reproduction

https://github.com/rtsao/vite-bug-repro-cjs-workspaces (for scenario 1) https://github.com/rtsao/vite-bug-repro-ssr-pnp and https://github.com/rtsao/vite-bug-repro-ssr-pnpm (for scenario 2)

System Info

System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 36.02 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/Library/Caches/fnm_multishells/1157_1660588473591/bin/node
    Yarn: 3.2.2 - ~/Library/Caches/fnm_multishells/1157_1660588473591/bin/yarn
    npm: 8.11.0 - ~/Library/Caches/fnm_multishells/1157_1660588473591/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.6 

Used Package Manager

yarn

Logs

vite-bug-repro-ssr-pnp main
❯ corepack enable
yarn install
yarn node app/server.mjs
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ vite@npm:3.0.8 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ which@npm:2.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wide-align@npm:1.1.5 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrappy@npm:1.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yallist@npm:4.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ esbuild@npm:0.14.54 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 616ms
➤ YN0000: Done with warnings in 0s 788ms
http://localhost:5173
ReferenceError: module is not defined
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:159:3
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:161:4
    at instantiateModule (file:///Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/__virtual__/vite-virtual-f00fbd239e/0/cache/vite-npm-3.0.8-cf480b5a77-ec3f57d52f.zip/node_modules/vite/dist/node/chunks/dep-74663fff.js:50512:15)
ReferenceError: module is not defined
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:157:3
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:159:4
    at instantiateModule (file:///Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/__virtual__/vite-virtual-f00fbd239e/0/cache/vite-npm-3.0.8-cf480b5a77-ec3f57d52f.zip/node_modules/vite/dist/node/chunks/dep-74663fff.js:50512:15) 

Validations

Forked On 19 Aug 2022 at 08:23:39

Rtsao

Put together a fix: https://github.com/vitejs/vite/pull/9763

TL;DR approach of resolving all nested deps from root is broken with pnpm and Yarn PnP

Commented On 19 Aug 2022 at 08:23:39

Rtsao

test(ssr): add failing external nested cjs test

Pushed On 19 Aug 2022 at 08:07:27
Create Branch

Rtsao

A reproduction of broken SSR with CommonJS dependencies and pnpm

On 19 Aug 2022 at 07:14:55
Create Branch

Rtsao

A reproduction of broken SSR with CommonJS dependencies and pnpm

On 19 Aug 2022 at 07:14:43
Pull Request

Rtsao

fix(ssr): ensure sup-dependencies are correctly externalized if not resolvable from root

Created On 19 Aug 2022 at 06:56:43

Rtsao

fix: legacy no emit worker (#9500)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix(ssr): rename objectPattern dynamic key (fixes #9585) (#9609)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix: json HMR (fixes #9521) (#9610)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix(optimizer): ignore EACCES errors while scanner (fixes #8916) (#9509)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix(plugin-react): wrong substitution causes React is not defined (#9386)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix: use browser field if it is not likely UMD or CJS (fixes #9445) (#9459)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

feat: show warning on 431 response (#9324)

Co-authored-by: Bjorn Lu bjornlu.dev@gmail.com

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix: don't count class declarations as react fast refresh boundry (fixes #3675) (#8887)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix(legacy): skip esbuild transform for systemjs (#9635)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

chore: narrow down rollup version (#9637)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

release: v3.0.6

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

release: plugin-vue@3.0.2

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

release: plugin-react@2.0.1

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

release: plugin-legacy@2.0.1

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

release: create-vite@3.0.1

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

refactor(legacy): remove code for Vite 2 (#9640)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

chore: remove vitest global options (#9620)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix(config): don't use file url for external files with cjs output (#9642)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

chore: fix typo in error message (#9645)

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

release: v3.0.7

Pushed On 19 Aug 2022 at 05:24:46

Rtsao

fix: legacy no emit worker (#9500)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix(ssr): rename objectPattern dynamic key (fixes #9585) (#9609)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix: json HMR (fixes #9521) (#9610)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix(optimizer): ignore EACCES errors while scanner (fixes #8916) (#9509)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix(plugin-react): wrong substitution causes React is not defined (#9386)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix: use browser field if it is not likely UMD or CJS (fixes #9445) (#9459)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

feat: show warning on 431 response (#9324)

Co-authored-by: Bjorn Lu bjornlu.dev@gmail.com

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix: don't count class declarations as react fast refresh boundry (fixes #3675) (#8887)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix(legacy): skip esbuild transform for systemjs (#9635)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

chore: narrow down rollup version (#9637)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

release: v3.0.6

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

release: plugin-vue@3.0.2

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

release: plugin-react@2.0.1

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

release: plugin-legacy@2.0.1

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

release: create-vite@3.0.1

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

refactor(legacy): remove code for Vite 2 (#9640)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

chore: remove vitest global options (#9620)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

fix(config): don't use file url for external files with cjs output (#9642)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

chore: fix typo in error message (#9645)

Pushed On 19 Aug 2022 at 05:24:14

Rtsao

release: v3.0.7

Pushed On 19 Aug 2022 at 05:24:14
Create Branch
Rtsao In rtsao/vite Create Branchfix-externals-pnp

Rtsao

Next generation frontend tooling. It's fast!

On 19 Aug 2022 at 05:09:46

Rtsao

implement cmd_prefix hook

This hooks allows jazelle commands to be prefixed or wrapped.

Examples:

  • always prefix an env var,
// manifest.json
{
  "hooks": {
    "cmd_prefix": "echo 'FOO=1'"
  }
} 
  • always time commands
// manifest.json
{
  "hooks": {
    "cmd_prefix": "time"
  }
} 
  • always print command instead of running
// manifest.json
{
  "hooks": {
    "cmd_prefix": "echo 'echo'"
  }
} 

Since the script is a shell script, it's also possible to conditionally prefix, etc

Merged On 17 Aug 2022 at 09:04:07

Rtsao

Commented On 17 Aug 2022 at 09:04:07
Issue Comment

Rtsao

CommonJS dependencies crash SSR server

Describe the bug

CommonJS dependencies encountered during SSR can crash the server (e.g. ReferenceError: module is not defined or ReferenceError: require is not defined, depending on which is first) if workspaces are used in some capacity.

I have identified two specific scenarios where this will occur:

  1. The CJS dependency is a workspace (i.e. appcjs-workspace)
  2. The CJS dependency is a sub-dependency of a workspace dependency (i.e. appother-workspacecjs-npm-dependency) AND Yarn PnP is used.

While possibly confusing, the first scenario is arguably intentional behavior because workspaces are typically implemented with symlinks and this logic indicates that symlinked packages should never be externalized: https://github.com/vitejs/vite/blob/c6870f37161f479b4306826e1e4d8e42ed01d6a8/packages/vite/src/node/plugins/resolve.ts#L656-L659

However, the second scenario is almost certainly a bug.

Reproduction

https://github.com/rtsao/vite-bug-repro-cjs-workspaces (for scenario 1) https://github.com/rtsao/vite-bug-repro-ssr-pnp (for scenario 2)

System Info

System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 36.02 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/Library/Caches/fnm_multishells/1157_1660588473591/bin/node
    Yarn: 3.2.2 - ~/Library/Caches/fnm_multishells/1157_1660588473591/bin/yarn
    npm: 8.11.0 - ~/Library/Caches/fnm_multishells/1157_1660588473591/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.6 

Used Package Manager

yarn

Logs

vite-bug-repro-ssr-pnp main
❯ corepack enable
yarn install
yarn node app/server.mjs
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ vite@npm:3.0.8 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ which@npm:2.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wide-align@npm:1.1.5 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ wrappy@npm:1.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yallist@npm:4.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ esbuild@npm:0.14.54 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 616ms
➤ YN0000: Done with warnings in 0s 788ms
http://localhost:5173
ReferenceError: module is not defined
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:159:3
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:161:4
    at instantiateModule (file:///Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/__virtual__/vite-virtual-f00fbd239e/0/cache/vite-npm-3.0.8-cf480b5a77-ec3f57d52f.zip/node_modules/vite/dist/node/chunks/dep-74663fff.js:50512:15)
ReferenceError: module is not defined
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:157:3
    at /@fs/Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/cache/locale-npm-0.1.0-6c7fdc5891-42af4432bc.zip/node_modules/locale/lib/index.js:159:4
    at instantiateModule (file:///Users/rtsao/code/vite-bug-repro-ssr-pnp/.yarn/__virtual__/vite-virtual-f00fbd239e/0/cache/vite-npm-3.0.8-cf480b5a77-ec3f57d52f.zip/node_modules/vite/dist/node/chunks/dep-74663fff.js:50512:15) 

Validations

Forked On 17 Aug 2022 at 03:38:20

Rtsao

I'm aware of a workaround to forcibly externalize these deps (as they should be): {ssr: {external: ["the-dep"]}) but this is rather cumbersome for large projects where there could be hundreds of CommonJS sub-dependencies. Very few npm packages are ESM.

I think the heuristics for whether dependencies should be externalized is broken somehow.

Commented On 17 Aug 2022 at 03:38:20

Rtsao

Update README.md

Pushed On 17 Aug 2022 at 03:58:52

Rtsao

Update README.md

Pushed On 17 Aug 2022 at 03:44:53
Create Branch

Rtsao

A reproduction of broken SSR with CommonJS dependencies and Yarn PnP.

On 17 Aug 2022 at 03:43:29
Create Branch

Rtsao

A reproduction of broken SSR with CommonJS dependencies and Yarn PnP.

On 17 Aug 2022 at 03:43:22

Rtsao

Simplify repro

Pushed On 17 Aug 2022 at 02:38:22