question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to require/import?

See original GitHub issue

I’ve been using httpVueLoader for a side project where I just don’t need a compile step and it’s been very convenient!

As the app has been getting more complex, I’ve been wanting to modularize some parts, but require doesn’t seem to work inside of a .Vue file’s script block. I’m assuming it’s not supported, but sort of hoping I’m just doing it wrong…

<script>
var mixins = require('./test.js');

module.exports = {
    mixins,
});
</script>

Nothing actually breaks, but ./test.js doesn’t get loaded and my mixins don’t get executed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PwntasticKevcommented, Sep 4, 2019

Hello from the future! I’m a bit new to the vue/php world and am using your library to import components in. Is there any new feature allowing the es6 support for importing libraries? I’m guessing it could be more along the php/babel side not being able to compile things correctly. I get an unexpected token when importing within a .vue file then loading it inside a php file using vue SFC

0reactions
FranckFreiburgercommented, Jul 20, 2018

it seems that Vue-Fuse component uses ES6 import at many places. http-vue-loader is only able to process the entry point of the component. Then you can try one of the following solution:

  • use webpack to create an ES5 version of e Vue-Fuse component (aka without import)
  • ask Vue-Fuse component maintainer to provide an ES5 version of the component
  • write your own Vue-Fuse component using only ES5 (note that fuse.min.js is ES5)
Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript require vs import - Flexiple
One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() ...
Read more >
JavaScript Require vs. Import - Bits and Pieces
1. Require statements can be called anywhere in the code ... Usually, we call the import or require statements at the beginning of...
Read more >
Using Node.js require vs. ES6 import/export - Stack Overflow
Your answer is totally valid, but I think we're comparing two different characteristics. All import/export is converted to require , granted. But what...
Read more >
Difference between node.js require and ES6 import and export
Require is Non-lexical, it stays where they have put the file. Import is lexical, it gets sorted to the top of the file....
Read more >
Node.js: How to Use "Import" and "Require" in the Same File
Cases where it is necessary to use both “require” and “import” in a single file, are quite rare and it is generally not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found