Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

How to import/require/src? #74

Closed
xeroxstar opened this issue Oct 11, 2019 · 5 comments
Closed

How to import/require/src? #74

xeroxstar opened this issue Oct 11, 2019 · 5 comments

Comments

@xeroxstar
Copy link

xeroxstar commented Oct 11, 2019

I am not able to start going with this module, i tried everything to import it but nothing works:
i run npm install leader-line
After i try to import it and getting errors from every angle, i am using Vue framework and not sure what i am missing here:

import LeaderLine from '../../node_modules/leader-line/leader-line.min.js'
Error: node_modules_leader_line_leader_line_min_js__WEBPACK_IMPORTED_MODULE_1_.LeaderLine is not a constructor
import { LeaderLine } from '../../node_modules/leader-line/leader-line.min.js';
Error: Uncaught TypeError: LeaderLine is not a constructor

<script src="'../../node_modules/leader-line/leader-line.min.js"></script>

Error:Uncaught ReferenceError: LeaderLine is not defined

@xeroxstar
Copy link
Author

So i got this boy up and running with Vue, you just have to add at the leader-line.min.js a line at the bottom of the file:
module.exports = LeaderLine;

then run:
let LeaderLine = require('LeaderLine');
new LeaderLine (this.$refs.pointA,this.$refs.pointB) :)

@anseki
Copy link
Owner

anseki commented Oct 12, 2019

Hi @xeroxstar, thank you for the comment.

The best and easy way to import it is using Webpack and skeleton-loader.
#8 (comment)

At least, you should use export default instead of module.exports in your code because that is CommonJS that might be not supported in some environment.

@anseki
Copy link
Owner

anseki commented Oct 12, 2019

Also, if you added the <script> element, you don't have to import that because it was already loaded.
This is the JavaScript specification.

@xeroxstar
Copy link
Author

Thanks, by the way, this is an amazing module.

@anseki
Copy link
Owner

anseki commented Oct 14, 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

2 participants