Rollup-plugin-vue: imported rollup-plugin-vue/runtime/normalize.js is error

Created on 28 Oct 2019  ·  24Comments  ·  Source: vuejs/rollup-plugin-vue

Version

5.1.2

Reproduction link

https://jsfiddle.net/chrisvfritz/50wL7mdz/

Steps to reproduce

export default {
    input: components,
    output: {
        dir: 'lib/components',
        format: 'esm'
    },
    plugins: [
           vue()
    ]
};

image

image

What is expected?

import __vue_normalize__ from "rollup-plugin-runtime/runtime/normalize"

What is actually happening?

import __vue_normalize__ from 'C:Users
ongzongquanDesktopproject ue-components
ode_modules
ollup-plugin-vue
untime
ormalize.js';

image

High Blocked Bug Repro Needed

Most helpful comment

same problem

All 24 comments

Downgrading to latest rollup-plugin-vue 4.x fixed this for me.

I was also getting the following in my built files:
import __vue_normalize__ from '../node_modules/rollup-plugin-vue/runtime/normalize.js';

I experimented with downgrading to 5.1.1, which fixed for me:
npm i [email protected] --save-dev

I now get the expected:
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.mjs';

@jameswragg is right, 5.1.2 introduced a dependency on vue-runtime-helpers in my esm and umd builds which I would prefer not to include, but maybe I just need to understand the issue better? Either way 5.1.2 appears to have a breaking change.

So can maintainers provide more information on this one?
What exactly is this?!
import __vue_normalize__ from './node_modules/rollup-plugin-vue/runtime/normalize.js';
So everyone who is using my bundle should install this lib to make bundle work?!
Or we should add this via rollup external or what?

in window pc not work @5.1.2

This is still an issue - is there a fix coming for this anytime soon?

I think the unexpected path in import statement is caused by require.resolve: https://github.com/vuejs/rollup-plugin-vue/blob/master/src/index.ts#L179. Can someone verify if changing require.resolve to path.resovle(__dirname, '...') to works on windows?

@hosein2398 You can bundle or externalize it. To bundle include rollup-plugin-node-resolve in your config. To externalized add it as a dependency and include in rollup external plugin.

I suggest to externalize it.

Hello,

These failed :
opts.normalizer = '~' + path.resolve(__dirname, '../runtime/normalize');
opts.normalizer = '~' + path.join(__dirname, '../runtime/normalize');

I suppose it's because of the ~

Is opts.normalizer supposed to be a String, a Function or an Object ?

If it's a String wouldn't the solution looks like this ? :
opts.normalizer = '"' + path.join(__dirname, '../runtime/normalize') + '"';

same problem

The problem occurs on Windows. On Ubuntu 18.04 everything works as expected.
I hope this helps to find a solution.

@guaijie

vuePlugin( {
needMap : false,
normalizer : '~rollup-plugin-vue/runtime/normalize',
styleInjector : '~rollup-plugin-vue/runtime/browser',
} )

我目前是这样处理的,可以完美解决,请看截图

1
2
3

Hi everyone,

I was also experiencing this problem and adding rollup-plugin-node-resolve solved it.

My configuration is now :

import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import VuePlugin from 'rollup-plugin-vue'
import pkg from './package.json'

export default {
  input: 'src/main.js',
  output: {
    file: pkg.main,
    format: 'cjs'
  },
  plugins: [
    resolve(),
    commonjs(),
    VuePlugin()
  ]
}

I wish I could explain why though...

Same problem here.

@gslama-akqa adding rollup-plugin-node-resolve didn't solve it for me. Downgrading the versions did.

Hi @ProticM,

Not sure why this is working for me.

In case it can help with investigation, I pushed a working demo here.

A collegue seems to have the vue normalizeComponent function in the built file itself. He is on a Mac, I am on windows (broken the same as OP). We both have 5.0.1 and I cannot understand why we have different built files.

Node 10.17.0

rollup ^1.23.0
rollup-plugin-commonjs ^10.1.0
rollup-plugin-vue ^5.0.1 (Though have tried the latest 5.1.4, with no difference)

I have also tried above suggestions of installing rollup-plugin-node-resolved ^5.2.0, which for some reason requires rollup-plugin-json ^4.0.0

I do use nvm for windows, so will bite the bullet and reinstall node without nvm 😢

Should note that I only just recently nuked my instance of the repo and re-cloned due to other issues. It did work before.

I just restored the deleted files and indeed, the package.json for rollup-plugin-vue said 5.0.1 and the built file had its own normalizeComponent instead of importing it, so I am rather perplexed as to what the conditions were for it to work!

Any thoughts welcome!

Update: Forced using 5.1.1 and it seems to have worked. I just didn't fully understand how yarn worked so misread the lock file, meaning everything was using the latest 5.1.4

with [email protected], I am getting the same problem when I build my package using npm. Using yarn solved the problem for me.

with [email protected], I am getting the same problem when I build my package using npm. Using yarn solved the problem for me.

Super elegant solution, m8 🤣

with [email protected], I am getting the same problem when I build my package using npm. Using yarn solved the problem for me.

Super elegant solution, m8 🤣

Neither switching to yarn nor downgrading the package version are solutions for this problem. It's just a feedback about the problem that may help fixing it.

TL;DR - this should be rolled back and released as version 6.0.0 since it is a breaking change.


Rationale

The real problem here is that this was released as a semver-_patch_ change, when it probably should have been a semver-_major_ change due to the fact that it is breaking - it forces on us a new dependency. I had to release a patch for my cli utility locking rollup-plugin-vue to 5.1.1 because of this.

If I have a simple 'counter' demo component similar to the one in the official vue docs - no external requirements at all, using it should not not introduce any dependencies beyond vue itself. So this is exactly what I did. When I built with 5.1.1 and compared it with that produced with 5.1.2+, the newer one complains about missing dependencies. It is a breaking change for me as a user of rollup-plugin-vue unless I now install @rollup/plugin-node-resolve and update my build process.

If I update my build process as suggested, and externalize the new vue-runtime-helpers dependency, this only passes the issue on to users of my components. It is now a breaking change for my own users! To be fair, I can choose to bundle the helpers, which fixes things and the output is exactly as it was before...but this was something that was only made possible by following this issue thread and waiting almost a month before the @rollup/plugin-node-resolve comment was made.

I understand the desire to externalize vue-runtime-helpers to produce smaller bundles. But this whole issue is a prime example of how a project can benefit from semver - breaking changes should come with documentation of what is breaking, why, and how users of a package can update their projects.

This comment is starting to sound like a rant, which it wasn't meant to be, so let me wrap up.

I would suggest that this change (3b0b4de) be rolled back to restore original usage for those who expect the 5.1.1 configuration and output - it's not even clear what bug it was trying to address. Then, if truly necessary, release this change as 6.0.0 with the bug and new dependency/configuration requirements clearly documented. That way, additional users of rollup-plugin-vue aren't blindsided with this, and everyone who wishes to update has the choice to either explicitly bundle the helpers, or pass the new dependency on to their own users with their own semver-major change as appropriate.

Couldn't agree with @mgdodge more.
We also had to lock version 5.1.1 in our build environment while we were hoping this would be resolved.

Updated docs and cookbook would be a big help for me. I've tried going the recommended 5.1.4 route with externalized dependencies but can't get it to work. So sticking with 5.1.1 for now.

Reverted to v5.1.1 source to release v5.1.5.

Will introduces new changes as BREAKING CHANGE.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fjc0k picture fjc0k  ·  4Comments

rayrutjes picture rayrutjes  ·  7Comments

yaquawa picture yaquawa  ·  4Comments

spentacular picture spentacular  ·  6Comments

iassasin picture iassasin  ·  6Comments