Error Javascript ReferenceError: require is not defined in miIO Device Library
i try to use miIO library from https://github.com/aholstenson/miio but when i try use it i got error ReferenceError: require is not defined
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
const mio = require('./lib');
mio.device({ address: '192.168.31.148' })
.then(device => console.log('Connected to', device))
.catch(err => handleErrorHere);
</script>
</body>
</html>
can anyone help me to explain why this code got an error ?
javascript
add a comment |
i try to use miIO library from https://github.com/aholstenson/miio but when i try use it i got error ReferenceError: require is not defined
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
const mio = require('./lib');
mio.device({ address: '192.168.31.148' })
.then(device => console.log('Connected to', device))
.catch(err => handleErrorHere);
</script>
</body>
</html>
can anyone help me to explain why this code got an error ?
javascript
Yes it's a NodeJS module, meaning it runs in Node (on a server), not in a browser.miio is MIT-licensed and requires at least Node 6.6.0.
– Jeremy Thille
Jan 3 at 15:48
@Deiv — Browserify won't turn most dependancies on Node APIs into things that work in a browser.
– Quentin
Jan 3 at 15:49
add a comment |
i try to use miIO library from https://github.com/aholstenson/miio but when i try use it i got error ReferenceError: require is not defined
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
const mio = require('./lib');
mio.device({ address: '192.168.31.148' })
.then(device => console.log('Connected to', device))
.catch(err => handleErrorHere);
</script>
</body>
</html>
can anyone help me to explain why this code got an error ?
javascript
i try to use miIO library from https://github.com/aholstenson/miio but when i try use it i got error ReferenceError: require is not defined
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
const mio = require('./lib');
mio.device({ address: '192.168.31.148' })
.then(device => console.log('Connected to', device))
.catch(err => handleErrorHere);
</script>
</body>
</html>
can anyone help me to explain why this code got an error ?
javascript
javascript
asked Jan 3 at 15:46
Fian JulioFian Julio
243
243
Yes it's a NodeJS module, meaning it runs in Node (on a server), not in a browser.miio is MIT-licensed and requires at least Node 6.6.0.
– Jeremy Thille
Jan 3 at 15:48
@Deiv — Browserify won't turn most dependancies on Node APIs into things that work in a browser.
– Quentin
Jan 3 at 15:49
add a comment |
Yes it's a NodeJS module, meaning it runs in Node (on a server), not in a browser.miio is MIT-licensed and requires at least Node 6.6.0.
– Jeremy Thille
Jan 3 at 15:48
@Deiv — Browserify won't turn most dependancies on Node APIs into things that work in a browser.
– Quentin
Jan 3 at 15:49
Yes it's a NodeJS module, meaning it runs in Node (on a server), not in a browser.
miio is MIT-licensed and requires at least Node 6.6.0.
– Jeremy Thille
Jan 3 at 15:48
Yes it's a NodeJS module, meaning it runs in Node (on a server), not in a browser.
miio is MIT-licensed and requires at least Node 6.6.0.
– Jeremy Thille
Jan 3 at 15:48
@Deiv — Browserify won't turn most dependancies on Node APIs into things that work in a browser.
– Quentin
Jan 3 at 15:49
@Deiv — Browserify won't turn most dependancies on Node APIs into things that work in a browser.
– Quentin
Jan 3 at 15:49
add a comment |
2 Answers
2
active
oldest
votes
The documentation you link to says:
miio is MIT-licensed and requires at least Node 6.6.0.
You are trying to run it in a web browser instead of in Node.
You need to run it in Node.
add a comment |
If you want to use require without nodejs then you'll need to use Browserify/RequireJS, as outlined in this question: How to use JS require() without Node.js
The OP wants to use the library they have found. Support forrequire
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.
– Quentin
Jan 3 at 15:51
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
That question specifically addresses the use ofrequire
and lets you userequire
in a browser. As mentioned in my previous comment, supportingrequire
is not sufficient to solve the problem posed by the question. If yourequire
something in a browser that won't run in a browser, then it still won't run.
– Quentin
Jan 3 at 15:54
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025565%2ferror-javascript-referenceerror-require-is-not-defined-in-miio-device-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The documentation you link to says:
miio is MIT-licensed and requires at least Node 6.6.0.
You are trying to run it in a web browser instead of in Node.
You need to run it in Node.
add a comment |
The documentation you link to says:
miio is MIT-licensed and requires at least Node 6.6.0.
You are trying to run it in a web browser instead of in Node.
You need to run it in Node.
add a comment |
The documentation you link to says:
miio is MIT-licensed and requires at least Node 6.6.0.
You are trying to run it in a web browser instead of in Node.
You need to run it in Node.
The documentation you link to says:
miio is MIT-licensed and requires at least Node 6.6.0.
You are trying to run it in a web browser instead of in Node.
You need to run it in Node.
edited Jan 3 at 15:58
community wiki
2 revs
Quentin
add a comment |
add a comment |
If you want to use require without nodejs then you'll need to use Browserify/RequireJS, as outlined in this question: How to use JS require() without Node.js
The OP wants to use the library they have found. Support forrequire
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.
– Quentin
Jan 3 at 15:51
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
That question specifically addresses the use ofrequire
and lets you userequire
in a browser. As mentioned in my previous comment, supportingrequire
is not sufficient to solve the problem posed by the question. If yourequire
something in a browser that won't run in a browser, then it still won't run.
– Quentin
Jan 3 at 15:54
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
add a comment |
If you want to use require without nodejs then you'll need to use Browserify/RequireJS, as outlined in this question: How to use JS require() without Node.js
The OP wants to use the library they have found. Support forrequire
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.
– Quentin
Jan 3 at 15:51
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
That question specifically addresses the use ofrequire
and lets you userequire
in a browser. As mentioned in my previous comment, supportingrequire
is not sufficient to solve the problem posed by the question. If yourequire
something in a browser that won't run in a browser, then it still won't run.
– Quentin
Jan 3 at 15:54
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
add a comment |
If you want to use require without nodejs then you'll need to use Browserify/RequireJS, as outlined in this question: How to use JS require() without Node.js
If you want to use require without nodejs then you'll need to use Browserify/RequireJS, as outlined in this question: How to use JS require() without Node.js
edited Jan 3 at 15:53
answered Jan 3 at 15:49
DeivDeiv
918516
918516
The OP wants to use the library they have found. Support forrequire
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.
– Quentin
Jan 3 at 15:51
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
That question specifically addresses the use ofrequire
and lets you userequire
in a browser. As mentioned in my previous comment, supportingrequire
is not sufficient to solve the problem posed by the question. If yourequire
something in a browser that won't run in a browser, then it still won't run.
– Quentin
Jan 3 at 15:54
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
add a comment |
The OP wants to use the library they have found. Support forrequire
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.
– Quentin
Jan 3 at 15:51
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
That question specifically addresses the use ofrequire
and lets you userequire
in a browser. As mentioned in my previous comment, supportingrequire
is not sufficient to solve the problem posed by the question. If yourequire
something in a browser that won't run in a browser, then it still won't run.
– Quentin
Jan 3 at 15:54
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
The OP wants to use the library they have found. Support for
require
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.– Quentin
Jan 3 at 15:51
The OP wants to use the library they have found. Support for
require
is not sufficient. It also needs the ability to handle network packets. That's impossible in a web browser which can only do HTTP and web sockets.– Quentin
Jan 3 at 15:51
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
The answers there mention you can use these to loading modules for use in the browser. See this specific answer: stackoverflow.com/a/21818631/7207514
– Deiv
Jan 3 at 15:53
That question specifically addresses the use of
require
and lets you use require
in a browser. As mentioned in my previous comment, supporting require
is not sufficient to solve the problem posed by the question. If you require
something in a browser that won't run in a browser, then it still won't run.– Quentin
Jan 3 at 15:54
That question specifically addresses the use of
require
and lets you use require
in a browser. As mentioned in my previous comment, supporting require
is not sufficient to solve the problem posed by the question. If you require
something in a browser that won't run in a browser, then it still won't run.– Quentin
Jan 3 at 15:54
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
How is it not sufficient to solve the problem? OP is having issues with require, to fix that and load the module they must use RequireJS or other similar tools. You are simply saying what the issue is, but I am linking a solution that can help fix the issue. Obviously it won't run with using require, but this will allow OP to load the module as they clearly wish to achieve.
– Deiv
Jan 3 at 15:56
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
And after they fix that and load the module … it still won't work because the module needs other things that the browser does not support. You aren't linking to a solution, you are linking to a red herring that will just uncover a different error (but another symptom of the same problem) that can't be fixed in the browser.
– Quentin
Jan 3 at 15:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025565%2ferror-javascript-referenceerror-require-is-not-defined-in-miio-device-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes it's a NodeJS module, meaning it runs in Node (on a server), not in a browser.
miio is MIT-licensed and requires at least Node 6.6.0.
– Jeremy Thille
Jan 3 at 15:48
@Deiv — Browserify won't turn most dependancies on Node APIs into things that work in a browser.
– Quentin
Jan 3 at 15:49