single-spa / single-spa-vue

a single-spa plugin for vue.js applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_typeof is not defined

nightnei opened this issue · comments

STR:

  1. clone repository
  2. npm run build

AR: error _typeof is not defined

Problem connect with the typeof userOpts !== 'object'. And bundled js file has function _typeof inside of the umd module, instead of be defined out of the module.

Solutions:

  1. If everything is ok on your PC, probably today we gave different versions of dependencies. Check it, please. And if I am right - add package-lock file.

  2. And the second correct solution is to change checking for type of userOpts with help of using Object.prototype.toString.call(userOpts) !== '[object Object]'. Because your checking is incorrect, since it can't cought arrays and null values.

I cannot reproduce the problem you described here. One thing is that this project uses yarn, not npm. So you should not be doing npm install && npm run build, but rather yarn install && yarn build.

I tried out both yarn and npm locally and did not see an error. What version of node are you using?

node version is latest.

I just cloned repository and run npm run build.
@joeldenning Look at the builded code please:
Screenshot 2019-11-13 21 56 08

@joeldenning oh, with yarn we have another result. Check it please.
Screenshot 2019-11-13 22 05 54

So it works for you with yarn? I'll close this issue then. I have verified that the published version of the code does not use the _typeof function outside of the scope in which it's defined.

still, pretty strange. wonder what would cause the different package managers to output a different bundle??

yeah it is strange

@joeldenning @frehner I have found the problem.
I was right, about lock file. @babel/plugin-transform-modules-umd broke build.

You have lock file for yarn, so yarn build use 7.2.0 version, and npm run build use the latest 7.7.0 version.

Solution:

  1. set @babel/plugin-transform-modules-umd: 7.2.0** without ^.
  2. create lock file for npm.

Great work figuring that out. Thank you

@joeldenning @frehner excuse me, but I have found some more information in a commit to umd plugin :)

https://github.com/babel/babel/commit/e1839e5ec9c10ffadac51aa58fbc1e6753c6b27f#diff-ffd431f9489b95ec613d71c2ade19e4dR17

So, probably, you should avoid using comparison to object with help of typeof. And it's better to rewrite it as I did it in my first PR #24. But of course, it's up to you. It was just an interesting issue for me, so I decided to investigate problem deeply :)

I read that commit and I don't understand why using typeof is bad.