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

Cannot read properties of undefined (reading 'isSelfAccepting') #13030

Closed
gajus opened this issue Apr 27, 2023 · 27 comments
Closed

Cannot read properties of undefined (reading 'isSelfAccepting') #13030

gajus opened this issue Apr 27, 2023 · 27 comments

Comments

@gajus
Copy link
Contributor

gajus commented Apr 27, 2023

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/vite@4.2.2_@types+node@18.16.0_sass@1.62.0/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/vite@4.2.2_@types+node@18.16.0_sass@1.62.0/node_modules/vite/dist/node/chunks/dep-d305c21f.js:43464:30)

Reproduction

N/A

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

pnpm

### 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.
@gajus
Copy link
Contributor Author

gajus commented Apr 27, 2023

Just realized that we are not on the latest version of Vite.

Attempting to replicate this with Vite v4.3.3.

@gajus
Copy link
Contributor Author

gajus commented Apr 27, 2023

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/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/node_modules/vite/dist/node/chunks/dep-a178814b.js:61853:29)
2ea918c5 >       at TransformContext.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/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/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/node_modules/vite/dist/node/chunks/dep-a178814b.js:42877:30)
2ea918c5 >       at async loadAndTransform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/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/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/node_modules/vite/dist/node/chunks/dep-a178814b.js:61853:29)
2ea918c5 >       at TransformContext.transform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/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/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/node_modules/vite/dist/node/chunks/dep-a178814b.js:42877:30)
2ea918c5 >       at async loadAndTransform (file:///Users/gajus/Developer/contra/gaia/node_modules/.pnpm/vite@4.3.3_@types+node@18.16.0_sass@1.62.0/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

@gajus
Copy link
Contributor Author

gajus commented Apr 27, 2023

This appears to be some sort of a race condition. It does not happen if I access the web app in a single browser instance. It starts breaking when I try to run Playwright tests against the Vite instance using 5 parallel instances.

@fc
Copy link
Contributor

fc commented Apr 27, 2023

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*

@gajus
Copy link
Contributor Author

gajus commented Apr 28, 2023

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.

@justb3a
Copy link

justb3a commented Apr 28, 2023

+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.

@lancetipton
Copy link

+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.

image

@brillout
Copy link
Contributor

brillout commented Apr 28, 2023

Can someone reproduce this reliably?

@lancetipton
Copy link

@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

@justb3a
Copy link

justb3a commented Apr 28, 2023

@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. 🧐

@MrFlashAccount
Copy link

@justb3a Maybe the reason might be because 2 vite processes running simultaneously.

@patak-dev
Copy link
Member

Please try to create a minimal reproduction using vite.new or a github repo to share here. Also, is this something that started happening in Vite 4.3? It looks from @gajus' original issue that 4.2 was also affected.

@gajus
Copy link
Contributor Author

gajus commented Apr 28, 2023

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.

@justb3a
Copy link

justb3a commented May 2, 2023

@justb3a Maybe the reason might be because 2 vite processes running simultaneously.

It used to work without issues for a long time.

@jonavila
Copy link

jonavila commented May 3, 2023

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

@patak-dev
Copy link
Member

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

@justb3a
Copy link

justb3a commented May 4, 2023

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

> vite@4.3.4 build /home/vitejs/vite/packages/vite
> rimraf dist && run-s build-bundle build-types


> vite@4.3.4 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

> vite@4.3.4 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


> vite@4.3.4 build-types-temp /home/vitejs/vite/packages/vite
> tsc --emitDeclarationOnly --outDir temp/node -p src/node


> vite@4.3.4 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 🙏

@JasonObeid
Copy link

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:

  1. Run a playwright test
  2. It completes, and auto-generates some reports about the completed tests in its directory
  3. The new / updated files generated by playwright triggers the generate script to run
  4. The generate script updates several files being watched by Vite server, and somehow also updates vite.config
  5. Some files get Hot Module Reloaded by Vite server, and I think maybe concurrently or right after
  6. 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

@patak-dev
Copy link
Member

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).

@gajus
Copy link
Contributor Author

gajus commented May 10, 2023

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 :-)

@mauricekleine
Copy link

mauricekleine commented May 15, 2023

@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.

@Artur-
Copy link
Contributor

Artur- commented May 17, 2023

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')

@Artur-
Copy link
Contributor

Artur- commented May 17, 2023

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')

@Artur-
Copy link
Contributor

Artur- commented May 17, 2023

When using the PR, the isSelfAccepting issue comes from

importerModule.isSelfAccepting = false
when importer is /home/circleci/pre-lit/frontend/themes/pre-lit/styles.css?inline

@Artur-
Copy link
Contributor

Artur- commented May 17, 2023

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

normalizeHmrUrl(importerModule.url),

@Artur-
Copy link
Contributor

Artur- commented May 17, 2023

Seems this is caused (or triggered) by #12599. The commit before that, 276725f works.

@patak-dev
Copy link
Member

This issue should be fixed by #13231, please report back, and let's reopen it if you still hit this bug after the next patch.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests