Skip to content

Commit c344809

Browse files
committed
Fixing missing-loader for vue-loader 16
1 parent 85d42cd commit c344809

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/friendly-errors/transformers/missing-loader.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ function isMissingLoaderError(e) {
2626
}
2727

2828
function isErrorFromVueLoader(filename) {
29-
return filename.includes('??vue-loader-options');
29+
// vue2
30+
if (filename.includes('??vue-loader-options')) {
31+
return true;
32+
}
33+
34+
// vue3
35+
if (filename.includes('vue-loader/dist??')) {
36+
return true;
37+
}
3038
}
3139

3240
function getFileExtension(filename) {
3341
// ??vue-loader-options
3442
if (isErrorFromVueLoader(filename)) {
3543
// vue is strange, the "filename" is reported as something like
36-
// /path/to/project/node_modules/vue-loader/lib??vue-loader-options!./vuejs/App.vue?vue&type=style&index=1&lang=scss
44+
// vue2: /path/to/project/node_modules/vue-loader/lib??vue-loader-options!./vuejs/App.vue?vue&type=style&index=1&lang=scss
45+
// vue3: /path/to/project/node_modules/vue-loader/dist??ref--4-0!./vuejs/App.vue?vue&type=style&index=1&lang=scss
3746
const langPos = filename.indexOf('lang=') + 5;
3847
let endLangPos = filename.indexOf('&', langPos);
3948
if (endLangPos === -1) {

test/friendly-errors/transformers/missing-loader.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('transform/missing-loader', () => {
8282
expect(actualError.loaderName).to.deep.equal('typescript');
8383
});
8484

85-
it('vue-loader is handled correctly', () => {
85+
it('vue-loader15 is handled correctly', () => {
8686
const startError = {
8787
name: 'ModuleParseError',
8888
message: 'Module parse failed: Unexpected character \'#\' (35:0)\nYou may need an appropriate loader to handle this file type.\n| \n| \n| #app {\n| display: flex;\n| color: #2c3e90;',
@@ -96,6 +96,20 @@ describe('transform/missing-loader', () => {
9696
expect(actualError.isVueLoader).to.be.true;
9797
});
9898

99+
it('vue-loader16 is handled correctly', () => {
100+
const startError = {
101+
name: 'ModuleParseError',
102+
message: 'Module parse failed: Unexpected character \'#\' (35:0)\nYou may need an appropriate loader to handle this file type.\n| \n| \n| #app {\n| display: flex;\n| color: #2c3e90;',
103+
file: '/path/to/project/node_modules/vue-loader/dist??ref--4-0!./vuejs/App.vue?vue&type=style&index=1&lang=scss'
104+
};
105+
const actualError = transform(Object.assign({}, startError));
106+
107+
expect(actualError.name).to.deep.equal('Loader not enabled');
108+
expect(actualError.type).to.deep.equal('loader-not-enabled');
109+
expect(actualError.loaderName).to.deep.equal('sass');
110+
expect(actualError.isVueLoader).to.be.true;
111+
});
112+
99113
it('vue-loader is handled correctly, more options after lang=', () => {
100114
const startError = {
101115
name: 'ModuleParseError',

0 commit comments

Comments
 (0)