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

Compiling error when the template of the .vue file has the attribute lang="html" #1443

Closed
eltonchan opened this issue Dec 3, 2018 · 13 comments

Comments

@eltonchan
Copy link

eltonchan commented Dec 3, 2018

Version

15.2.6

Reproduction link

https://github.com/eltonchan/test_vue_loader

Steps to reproduce

1、use vue cli3 create application (vue cli3 default use 15 version for vue-loader)
2、add html-loader to webpapck Configuration

chainWebpack: (config) => {
        config.module
            .rule('html')
            .test(/\.html$/)
            .use('html-loader')
            .loader('html-loader')
            .end();
    },

3、.vue file template add lang="html" attribute

<template lang="html">

4、npm run serve

What is expected?

compiling success

What is actually happening?

error in ./src/App.vue?vue&type=template&id=7ba5bd90&lang=html&

Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error)
Error compiling template:


By the way, in 14 version No such problem。

@GreenMelon
Copy link

Did U find any solution ? It is troubling me too 😭

@TotomInc
Copy link

TotomInc commented Dec 9, 2018

I'm struggling into this too, if I'm correct this is more from vue-template-compiler module, as I'm trying to build a vue-plugin using rollup and vue-template-compiler with .vue files.

EDIT: the only quick and easy fix right now (if you can touch the files) is to remove the lang="html" attribute.

@adamgoose
Copy link

adamgoose commented Dec 14, 2018

This proves problematic for a component that uses a language other than html. For example, we use pug for all of our vue component files.

I'm getting the same error, but also can see a message beneath the template:

error  in ./src/components/Presence.vue?vue&type=template&id=3482c7ab&lang=pug&

Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error)
  Error compiling template:

  v-toolbar-items(transition="slide-y-transition")
    v-avatar.mx-2.user-avatar(size="24" v-for="(id, i) in present" :key="i")
      img(:src="`https://someawesomeavatarserver.com/${id}`")

  - Component template requires a root element, rather than just text.

When I nest the entire component in a div, the compiler gives me the same error for another component, then another, then another...

It seems as though, in my case at least, the loader doesn't recognize v-toolbar-items(...) as a root element.

@oixan
Copy link

oixan commented Dec 25, 2018

this problem is happen to me too. How did you solve it?

@mgrinspan
Copy link

Happens to me as well, my workaround was setting my version constraint to "<15.0.0"

@oixan
Copy link

oixan commented Dec 25, 2018

Can you explain me the steps? Thanks!

@mgrinspan
Copy link

Modify your package.json file to have "vue-loader": "<15.0.0" in the require section. Then run npm install

@oixan
Copy link

oixan commented Dec 25, 2018

Now is finally working , thanks!

this is my final webpack config with chunks.

`const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sourceMaps(false, 'source-map')
.webpackConfig({
output: {
// Chunks in webpack
publicPath: '/',
chunkFilename: 'js/[name].[chunkhash].js',
},
module: {
rules: [
{
test: /.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: { appendTsSuffixTo: [/.vue$/] }
},
{
test: /.js$/,
loader: 'babel-loader',
exclude: file => (
/node_modules/.test(file) &&
!/.vue.js/.test(file)
)
},
],
},
plugins: [
],
resolve: {
extensions: ['*', '.js', '.jsx', '.vue', '.ts', '.tsx'],
},
});
`

@eltonchan
Copy link
Author

this problem is happen to me too. How did you solve it?

just remove lang="html" attribute can work

russsiq added a commit to russsiq/bxb-loading-layer that referenced this issue Jan 11, 2019
russsiq added a commit to russsiq/bxb-notification that referenced this issue Jan 11, 2019
russsiq added a commit to russsiq/bxb-scroll-to-top that referenced this issue Jan 11, 2019
@Chickyky
Copy link

Chickyky commented Jan 17, 2019

in file .vue if use <template> have attribute "lang" will build error text "module.exports = "" outside root element will be ignored
example in file app.vue I use
<template src="./templates/layout.pug" lang="pug"></template>
I use vue-loader@15.5.1 (newest)
...
I fix this by downgrade version vue-loader to 14.1.1
Work like a charm!
hope team vue-loader review it

@eltonchan
Copy link
Author

sorry . the Reproduction link is Invalid. I delete it

@posva posva closed this as completed Mar 5, 2019
@pxlrbt
Copy link

pxlrbt commented Nov 26, 2019

@posva This issue still seems to exists in vue-loader 15.7.2. When importing templates via src.

The following vue file:

<template src="./test.html"></template>

Results in this error

ERROR in ./resources/js/components/test/test.html?vue&type=template&id=7a788f03& (./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/html-loader!./resources/js/components/test/test.html?vue&type=template&id=7a788f03&)
Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error)

Errors compiling template:
  text "module.exports = "" outside root element will be ignored.
  1  |  module.exports = "<div class=\"test\"></div>";

Downgrading vue-loader to version 14 fixes the issue. Is this an vue-loader issue or could this be a config issue? I am using laravel-mix.

@posva
Copy link
Member

posva commented Nov 26, 2019

It could be a config issue but we would need a repro using the vue cli or bare webpack + vue-loader.
Maybe there is an open issue already in this repo. If there isn't and you manage to reproduce in an isolated environment like vue cli or bare webpack + vue loader (no laravel-mix), please, open a new issue.
Locking this one as it's outdated, the repro is missing and there isn't anything to add

@vuejs vuejs locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants