UnhandledPromiseRejectionWarning during Mocha unit:test --watch
See original GitHub issueAfter editing a component while running unit:test --watch, vuetify-loader causes an UnhandledPromiseRejectionWarning, and the webpack compile/rebuild hangs.
(node:8087) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received type function
at validateString (internal/validators.js:125:11)
at Object.relative (path.js:1162:5)
at JSON.stringify.splitted.map (~/loader-promise-rejection/node_modules/loader-utils/lib/stringifyRequest.js:30:29)
at Array.map (<anonymous>)
at Object.stringifyRequest (~/loader-promise-rejection/node_modules/loader-utils/lib/stringifyRequest.js:23:8)
at install (~/loader-promise-rejection/node_modules/vuetify-loader/lib/loader.js:38:57)
at Object.module.exports (~/loader-promise-rejection/node_modules/vuetify-loader/lib/loader.js:106:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:8087) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8087) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Simple steps to reproduce:
vue --version
3.7.0
vue create my-app
“Manually select features”, add Unit Testing, choose “Mocha + Chai” when prompted, everything else defaults.
cd my-app
vue add vuetify
Steps to here are in https://github.com/ajhoddinott/vuetify-loader-promise-rejection.
yarn test:unit --watch
vue add vuetify
has made changes to HelloWorld.vue without corresponding changes to example.spec.js, so the test fails.
Touch example.spec.js
, the webpack rebuild completes and the test is run (and fails) again as expected.
Touch HelloWorld.vue
, the webpack rebuild starts, but hangs/dies with the UnhandledPromiseRejectionWarning.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top GitHub Comments
We are also seeing this issue and while I don’t fully understand what the problem is I can at least recap what I discovered in case it’s useful.
First of all, the problem only shows up for us under these conditions:
test:unit --watch
as outlined above (it succeeds on the initial run)v-layout
)If the component doesn’t have use any vuetify components we don’t see the error.
Investigating into this a little the problem originates in the
vuetify-loader/lib/loader.js
file. Specifically (in v1.2.2 anyway) in the lines that install the components / directives line 106 / 107.The only thing I discovered about this call was that there seems to be a difference in the context that this code runs in the 2nd time through (upon saving the file). More specifically inspecting
this
at the point this code fails seems to indicate thatthis
refers to theglobal
object which causes the trouble once theinstall
function callsstringifyRequest(this, ...)
.So I think the solution is to make sure that the
install
function is called with the correctthis
context much like is done with thegetMatches.call
on those lines of code.Anyway, if I manually modify that
loader.js
file like this (note the.call(this,
modification):Then everything seems to work and error goes away.
However having not spent a lot of time understanding the vuetify-loader codebase I’m not certain about the ramifications of this and can’t be sure it doesn’t have other side effects that we’ve not seen yet.
I hope this helps. I’m happy to make a PR if this is the correct fix or for someone else to add it in if it is.
I’m experiencing the same/similar issue. It’s annoying to have to terminate the test watching and start it back up every time. I’m not sure if its vueitfy related though but I am using vuetify in the project. The only error I get is: