vuejs / rollup-plugin-vue

Roll .vue files
https://vuejs.github.io/rollup-plugin-vue
MIT License
846 stars 148 forks source link

Cannot import Vue SFC from current working directory #418

Open adamchipperfield opened 3 years ago

adamchipperfield commented 3 years ago

Version

5.0.0

Reproduction link

https://codesandbox.io/s/stupefied-shirley-39f24

Steps to reproduce

Build index.js into the dist folder. Run the bundled index.bundle.js file in a node folder with an App.vue file in the root.

What is expected?

To import the App.vue file without error

What is actually happening?

Error is thrown: "SyntaxError: Unexpected token '<'". It specifically points to the "<" in the opening <template> tag. In short, a bundled script I'm running doesn't import from the directory where the script was invoked.


The App.vue is pulling from the CWD which may have an issue, but it still runs through rollup with this plugin. Woth noting this is for a CLI but that shouldn't make a difference.

adamchipperfield commented 3 years ago

Bundled file attached...


Object.defineProperty(exports, '__esModule', { value: true });

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () {
            return e[k];
          }
        });
      }
    });
  }
  n['default'] = e;
  return Object.freeze(n);
}

const run = async () => {
  Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(`${process.cwd()}/App.vue`)); })
    .then((response) => {
      console.log(response);
    })
    .catch((error) => {
      console.log(error);
    });
};

exports.run = run;
adamchipperfield commented 3 years ago

Also, when doing the same but from the src directory it works fine... just not from CWD.