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

TypeError: Cannot read property 'lang' of null #16

Closed
chlab opened this issue Oct 21, 2017 · 23 comments
Closed

TypeError: Cannot read property 'lang' of null #16

chlab opened this issue Oct 21, 2017 · 23 comments
Labels

Comments

@chlab
Copy link

chlab commented Oct 21, 2017

I am trying out your webpack template to use jest for unit testing in a new little app and am getting this error when running npm run unit:

 FAIL  test/unit/specs/App.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'lang' of null

      at processScript (node_modules/jest-vue/lib/process.js:13:17)
      at Object.module.exports [as process] (node_modules/jest-vue/lib/process.js:27:18)
      at Object.<anonymous> (test/unit/specs/App.spec.js:1:114)

I reduced the file to an absolute minimum and I'm still getting the error.

App.spec.js

import App from '@/App'

App.vue

<template>
  <div id="app">
  </div>
</template>

package.json

...
"jest": "^21.2.0",
"jest-vue": "^0.7.0",
...

This is the offending line in jest-vue/lib/process.js:

function processScript (scriptPart) {
  if (scriptPart.lang === 'typescript' || scriptPart.lang === 'ts') {

Which seems to make sense since I do not define a lang attribute on my script tags.

@eddyerburgh
Copy link
Member

Hi, thanks for the bug report

I downloaded the webpack repo and failed to reproduce the issue. Would you be able to post the test file and component where you're getting this error, or even better post a reproduction repo?

@mikemenaker
Copy link

mikemenaker commented Oct 23, 2017

I ran into this issue as well.

I resolved it by changing the function process.js to:

function processScript (scriptPart) {
  if(scriptPart != null && scriptPart.hasOwnProperty("lang")) {
    if (scriptPart.lang === 'typescript' || scriptPart.lang === 'ts') {
      return compileTypescript(scriptPart.content)
    }

    if (scriptPart.lang === 'coffee' || scriptPart.lang === 'coffeescript') {
      return compileCoffeeScript(scriptPart.content)
    }

    return compileBabel(scriptPart.content)
  }

  return compileBabel(null)
}

I can make a pull request with this change or you might want to handle it a different way.

@eddyerburgh
Copy link
Member

I would appreciate a PR, and ideally a unit test with a case that fails. Thanks 🙂

@mikemenaker
Copy link

Cool, should have something today or tomorrow.

I think this issue popped up because I was using functional SFC with no script section (just a template).

@mikemenaker
Copy link

Looks like this will handle the issue I ran into:
#17

Any idea when a new release will go out?

Thanks!

@eddyerburgh
Copy link
Member

I've just released in 1.0.0 vue-jest.

Note I've changed the package name to vue-jest. You can still download jest-vue, but it won't be receiving further updates.

To install the new version:

npm install --save-dev vue-jest

I made a request to the original owner of vue-jest to transfer ownership to this repository so that the package name could be more idiomatic to other preprocessors like babel-vue and ts-vue.

@agualis
Copy link
Contributor

agualis commented Oct 26, 2017

@mikemenaker @chlab I confirm that SFC with no script section do work with version 1.0.0 vue-jest

But you need to define the template as <template functional>

@agualis
Copy link
Contributor

agualis commented Nov 2, 2017

There was another problem when testing nested functional components with mount. This pull request solves the issue:
#22

@chlab
Copy link
Author

chlab commented Nov 2, 2017

@eddyerburgh sorry for the late reply.

This is the repo that I'm encountering these problems. It has one unit test. I'm no longer seeing the lang error, but I'm still seeing the problems described in the PR.

Do you mind having a quick look? Can you run npm run unit without any problems?

Thanks!

@caioincau
Copy link

I am having the same problem here :(, the lang one.

@eddyerburgh
Copy link
Member

@icaioincau is this fixed for you in 1.0.1? If not, can you post the error?

@agualis
Copy link
Contributor

agualis commented Nov 5, 2017

Oh! I had oversimplified the parsing of the funcional templates and had forgotten some cases like passing a function or an array as props.

I just updated the pull request and I hope that this solves most of the common issues but more edge cases should arise so I'll keep an eye on this.

@eddyerburgh Sorry for the inconvenience, could you run a new release and test it with some complex functional templates please?

@eddyerburgh
Copy link
Member

I've released the changes in 1.0.2

@agualis
Copy link
Contributor

agualis commented Nov 5, 2017

Cool! I have a project with different funcional components and it works. Let's see if we find new edge cases. Thanks for the release!

@caioincau
Copy link

caioincau commented Nov 6, 2017

Hi @eddyerburgh my components is this:

<template>
  <section class="error-page__partial">
    <h1 class="error-page__main-title"> {{ $t('i18n.private') }} </h1>
    <h3>Lorem Ipsum at dolor sit amen</h3>
  </section>
</template>

He is on a main component that has a script.

<template>
  <section class="error-page" :class="modifiers">
    <div>
      <h1 class="error-page__main-title"> {{ $t('i18n.private') }} </h1>
      <h3 v-html="$t('i18n.private')"></h3>
    </div>
    <partial></partial> <!-- Here -->
  </section>
</template>

The error:


    TypeError: Cannot read property 'lang' of null

      at processScript (node_modules/jest-vue/lib/process.js:13:17)
      at Object.module.exports [as process] (node_modules/jest-vue/lib/process.js:27:18)
      at src/views/ErrorPage/ErrorPage.vue:8:14
      at Object.<anonymous> (src/views/ErrorPage/ErrorPage.vue:106:3)

Version used: 1.0.2

@agualis
Copy link
Contributor

agualis commented Nov 6, 2017

@icaioincau Try again changing your template to <template functional>...</template>

@caioincau
Copy link

It worked :D

@wienska
Copy link

wienska commented Nov 10, 2017

Hi! I've still got error with 'lang' in 1.0.2 version. Any way to fix it without adding functional to template?

@eddyerburgh
Copy link
Member

@Ca4tkin can you post the SFC that you're getting the error with?

@wienska
Copy link

wienska commented Nov 13, 2017

@eddyerburgh, here it is:

<template>
  <footer class="footer">I'm footer!</footer>
</template>

<style>
.footer {
  padding: 15px;
  border: 1px dashed red;
  text-align: center;
  margin-top: 30px;
}
</style>

@eddyerburgh
Copy link
Member

Thanks for posting the component @Ca4tkin 😀

I've pushed a fix in 1.0.3

@maxmilton
Copy link

Thanks @eddyerburgh 1.0.3 fixed the issue in my projects.

@wienska
Copy link

wienska commented Nov 14, 2017

@eddyerburgh thanks! It's fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants