Skip to content

编译失败, 报错 TypeError: Cannot read property 'content' of null #1747

Open
@idrunk

Description

@idrunk

Version

16.0.0-beta.8

Reproduction link

https://github.com/idrunk/vue-loader-bug-reproduction

Steps to reproduce

  • 配置webpack的cache.type为filesystem, 开启缓存
  • 初始化一个Vue3 Typescript的项目, 建立一个根单文件组件并使用ts版setup语法糖, 建立一个子单文件组件并使用ts版setup语法糖, 在根组件中导入子组件
  • 第一次编译, 正常通过能运行
  • (补充, 这里漏了关键一步, 就是这里需要改动inside.vue的模板内容, 即让缓存失效, 然后再编译才会失败, 否则直接用缓存的话则不会失败)
  • 后续编译, 编译失败, 报下述错误
TypeError: Cannot read property 'content' of null
    at Object.selectBlock (D:\Temp\vue3\1\node_modules\vue-loader\dist\select.js:25:45)
    at Object.loader (D:\Temp\vue3\1\node_modules\vue-loader\dist\index.js:60:25)

What is expected?

编译通过

What is actually happening?

编译失败


经过跟踪排查, 发现在前行(index.js:58)插入下述代码, 多次编译都能正常通过, 但我感觉这不是解决之道

        if (incomingQuery.type === 'script' && !descriptor.scriptCompiled && descriptor.scriptSetup) {
            descriptor.scriptCompiled = compiler_sfc_1.compileScript(descriptor, {
                babelParserPlugins: options.babelParserPlugins,
            })
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions