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

vue-loader error with script setup: Cannot read property 'content' of null #12591

Closed
lsdsjy opened this issue Jul 1, 2022 · 3 comments
Closed

Comments

@lsdsjy
Copy link
Contributor

lsdsjy commented Jul 1, 2022

Version

2.7.0-beta.8

Reproduction link

github.com

Steps to reproduce

yarn && yarn build

What is expected?

Build succeeds.

What is actually happening?

error  in ./src/App.vue?vue&type=script&setup=true&lang=ts&
Cannot read property 'content' of null

As shown in the reproduction repo, the problem occurs on a very specific condition:

  1. <script setup lang="ts">
  2. import
  3. : in a string and ; in event handler
@yyx990803
Copy link
Member

This seems to be caused by an outdated version of eslint-plugin-vue. Please update it to the latest version.

@lsdsjy
Copy link
Contributor Author

lsdsjy commented Jul 1, 2022

I've tried update eslint-plugin-vue to the latest version(9.1.1) and the problem remains. See lsdsjy/vue-template-handler-bug-reprod@814d1b1

@lsdsjy
Copy link
Contributor Author

lsdsjy commented Jul 1, 2022

I think it's caused by https://github.com/vuejs/vue/blob/main/packages/compiler-sfc/src/compileScript.ts#L1838

Event handler like $emit('update:a'); is recognized as a TypeScript type annotation syntax and passed to babelParser.parseExpression, which caused an error because it's a statement not an expression.

A possible fix is #12594 , which strips the strings in the code before detecting type syntax.

And I've found that Vue3 has the same problem. I think the fix can be ported to vuejs/core too.

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

Successfully merging a pull request may close this issue.

2 participants