添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

Describe the bug

Occasionally requests are failing with an error:

35a0d891 > TypeError: Cannot read properties of undefined (reading 'isSelfAccepting')
35a0d891 >     at TransformContext.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-d305c21f.js:41735:43)
35a0d891 >     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
35a0d891 >     at async Object.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-d305c21f.js:43464:30)

Reproduction

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 520.14 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.8.1 - ~/.nvm/versions/node/v19.8.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v19.8.1/bin/npm
    Watchman: 2023.03.13.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 112.0.5615.137
    Safari: 16.3
  npmPackages:
    @vitejs/plugin-react: ^3.1.0 => 3.1.0
    vite: ^4.2.2 => 4.2.2
### Used Package Manager ### Logs _No response_ ### Validations - [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md) - [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md). - [X] Read the [docs](https://vitejs.dev/guide). - [X] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate. - [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to [vuejs/core](https://github.com/vuejs/core) instead. - [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/). - [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Confirmed that the same error is present on v4.3.3

2ea918c5 >   Plugin: vite:import-analysis
2ea918c5 >   File: virtual:vite-plugin-ssr:importUserCode:client:client-routing
2ea918c5 >       at ModuleGraph.updateModuleInfo (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:61853:29)
2ea918c5 >       at TransformContext.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:40824:57)
2ea918c5 >       at async Object.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:42877:30)
2ea918c5 >       at async loadAndTransform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:53334:29)
2ea918c5 > 8:02:50 PM [vite] Internal server error: Cannot set properties of undefined (setting 'isSelfAccepting')
2ea918c5 >   Plugin: vite:import-analysis
2ea918c5 >   File: virtual:vite-plugin-ssr:importUserCode:client:client-routing
2ea918c5 >       at ModuleGraph.updateModuleInfo (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:61853:29)
2ea918c5 >       at TransformContext.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:40824:57)
2ea918c5 >       at async Object.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:42877:30)
2ea918c5 >       at async loadAndTransform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-a178814b.js:53334:29)
  System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.98 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.8.1 - ~/.nvm/versions/node/v19.8.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v19.8.1/bin/npm
    Watchman: 2023.03.13.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 112.0.5615.137
    Safari: 16.3
  npmPackages:
    @vitejs/plugin-react: ^3.1.0 => 3.1.0
    vite: ^4.3.3 => 4.3.3

We've also run into this issue. Does it seem to be related to vite cache for you at all? Have you tried deleting all cache files before running tests to workaround it? rm -rf ./node_modules/.vite*

I don't think so. I can pretty consistently replicate this when requesting the web app using several parallel processes. It appears to be some sort of a race condition.

+1, also getting

[vite] Internal server error: Cannot set properties of undefined (setting 'isSelfAccepting')

rm -rf ./node_modules/.vite* did not change anything.

I use vite (@latest) with ladle and npm. Next line in log is Plugin: vite:import-analysis, don't know if this might be related.

I found the following (already merged) old PR #7993 also having issues with isSelfAccepting and vite:import-analysis.

+1, for me as well.

Came to github to report the issue and found this issue already opened. Figured I'd add to it instead of creating a new one.
It seems to happen on random files and is not consistent. See image below.

@brillout - On my end, it unfortunately doesn't happen reliably, and I'm not even sure how to replicate it.

While debugging, I tried removing; then adding back in the same change that caused it, and it worked fine the second time.

When it does happen, I typically have to restart vite, and it works again for a while, but eventually out of the blue it will come back again. Maybe some type of memory leak? Hard to say, but hopefully that's helpful.

Happy to provide more information, if there's something else needed?

Thanks

@brillout on my end it fails quite reliable. 10% on start, 80% on first code change save, 10% on second code change save.

…but if I only serve the styleguide using ladle and vite (the one which fails), then it seems to work like a charm!

I use run-p to start several scripts in parallel, maybe something is going on here.

"dev": "run-p dev:*",
"dev:build": "esbuild …",
"dev:remix": "remix watch",
"dev:ladle": "ladle dev --viteConfig ./.ladle/vite.config.ts",

npm run dev -> ladle is failing
npm run dev:ladle -> ladle seems to work

edit: Removing remix watch solves the issue. All other scripts work perfectly next to each other using run-p. 🧐

Also, is this something that started happening in Vite 4.3? It looks from @gajus' original issue that 4.2 was also affected.

It is happening in Vite 4.2 and Vite 4.3.

In my case, it is easy to replicate this by running Playwright Tests in parallel against Vite instance, i.e. multiple instances of browser talking with the same Vite HMR instance at once.

So it is not something that can be replicated in isolation (as far as I can think), but rather how the client interacts with it.

In my case, it is easy to replicate this by running Playwright Tests in parallel against Vite instance, i.e. multiple instances of browser talking with the same Vite HMR instance at once.

Same. It happens when running Playwright tests

Would you try if this PR fixes your issue? #13085

Assuming I built everything correctly, it still throws [vite] Internal server error: Cannot set properties of undefined (setting 'isSelfAccepting') Plugin: vite:import-analysis.

I used StackBlitz Codeflow to build the bundle and types. Somehow, building the types does not work.

~/vitejs/vite/packages/vite fix/race-conditions-creating-module-in-graph-in-transform-request
❯ pnpm run build
> [email protected] build /home/vitejs/vite/packages/vite
> rimraf dist && run-s build-bundle build-types
> [email protected] build-bundle /home/vitejs/vite/packages/vite
> rollup --config rollup.config.ts --configPlugin typescript
/home/vitejs/vite/packages/vite/src/client/env.ts → dist/client/env.mjs...
created dist/client/env.mjs in 1.1s
/home/vitejs/vite/packages/vite/src/client/client.ts → dist/client/client.mjs...
created dist/client/client.mjs in 901ms
/home/vitejs/vite/packages/vite/src/node/index.ts, /home/vitejs/vite/packages/vite/src/node/cli.ts, /home/vitejs/vite/packages/vite/src/node/constants.ts → ./dist...
shimmed: json-stable-stringify/index.js
shimmed: postcss-load-config/src/index.js
shimmed: postcss-import/index.js
shimmed: fsevents-handler.js
shimmed: process-content.js
shimmed: lilconfig/dist/index.js
patched cjs context: node/chunks/dep-!~{001}~.js
patched cjs context: node/chunks/dep-!~{003}~.js
patched cjs context: node/chunks/dep-!~{004}~.js
patched cjs context: node/chunks/dep-!~{005}~.js
patched cjs context: node/chunks/dep-!~{002}~.js
created ./dist in 8.9s
/home/vitejs/vite/packages/vite/src/node/publicUtils.ts → ./dist...
created ./dist in 3.5s
> [email protected] build-types /home/vitejs/vite/packages/vite
> run-s build-types-temp build-types-pre-patch build-types-roll build-types-post-patch build-types-check
> [email protected] build-types-temp /home/vitejs/vite/packages/vite
> tsc --emitDeclarationOnly --outDir temp/node -p src/node
> [email protected] build-types-pre-patch /home/vitejs/vite/packages/vite
> tsx scripts/prePatchTypes.ts
// -> here it stops 🤷🏻‍♀️ so I copied the types file from the "original" 

Thanks for taking care of the issue 🙏

Hi @patak-dev, I've given a #13085 a try and it didn't seem to remove the issue. Let me know if I can help with any further logs or reproduction steps.

Given that some other users mentioned this was happening specifically within Playwright tests, here are some of my findings and how it was being produced:

Context:

  • Our local environment watches for file changes which then triggers a generate script to run
  • Vite server was watching for changes in the playwright test directory.
  • Reproduction steps:

  • Run a playwright test
  • It completes, and auto-generates some reports about the completed tests in its directory
  • The new / updated files generated by playwright triggers the generate script to run
  • The generate script updates several files being watched by Vite server, and somehow also updates vite.config
  • Some files get Hot Module Reloaded by Vite server, and I think maybe concurrently or right after
  • Vite server restarts due to updated config, and then the Cannot read properties of undefined (reading 'isSelfAccepting') error occurs.
  • I was able to avoid this by:

  • In the Vite config, ignore watching for changes in the playwright test directory,
  • and also ignoring these changes in our other watch command that re-runs a generate script
  • Hope this helps in some way!

    cc @gajus

    Thanks for the detailed comment @JasonObeid! @gajus, I wonder if something similar is happening in your case. Vite should still be able to cope with this scenario though (although the bug showed in this case that Jason's setup could be improved).

    @patak-dev I am in the same team with @JasonObeid :-)

    @patak-dev there seems to be a similar issue popping up while using Storybook with Vite. I've linked the issue above. Like the other commenters above, I'm also not able to consistently get this error to appear - but for me it results in not being able to run Storybook 90% of the time, until it randomly works. I've posted the output in the Storybook issue linked above, hopefully that might help getting to the bottom of this.

    We see this in every CI build of a given project starting from an update (not Vite update) yesterday. The output seems similar to what is described above

    Starting Vite
    [vite] target/vaadin-dev-server-settings.json changed, restarting server...
    [vite] vite.generated.ts changed, restarting server...
    [vite] server restarted.
    [vite] Internal server error: Cannot set properties of undefined (setting 'isSelfAccepting')
    Plugin: vite:import-analysis
    File: /tmp/unzipped-test-pre-lit11848266504889201629svc-project/pre-lit/node_modules/vite/dist/client/client.mjs
        at ModuleGraph.updateModuleInfo (file:///tmp/unzipped-test-pre-lit11848266504889201629svc-project/pre-lit/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:61869:29)
        at TransformContext.transform (file:///tmp/unzipped-test-pre-lit11848266504889201629svc-project/pre-lit/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:40825:57)
        at async Object.transform (file:///tmp/unzipped-test-pre-lit11848266504889201629svc-project/pre-lit/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:42883:30)
        at async loadAndTransform (file:///tmp/unzipped-test-pre-lit11848266504889201629svc-project/pre-lit/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:53349:29)
    

    The changed files are imported in vite.config.ts

    Sometimes instead of "internal server error", the error is only

    Cannot set properties of undefined (setting 'isSelfAccepting')
              

    With the PR version (#13085) I still see

    Cannot set properties of undefined (setting 'isSelfAccepting')
    

    sometimes the error is also combined with

    Cannot read properties of undefined (reading 'url')
              

    Cannot read properties of undefined (reading 'url') is reported for the same importer before the isSelfAccepting error, at