I'm using angular 5, I'm trying to use a javascript file that hold some methods that use a library from docuvieware. I ended up using javascript since I was unable to use it on typescript. So I have the following code:
const { docuVieware } = require('../../../docuvieware/docuvieware-min');
module.exports = { loadFile:
function loadFile(file) {
if (file != null) {
var params = {
Value: file,
Example: false
};
docuVieware.DocuViewareAPI.PostCustomServerAction("DocuVieware1",
true, "loadFile", params, function(result){ console.log("result: " +
JSON.stringify(result)); });
}
}
};
But whenever I open my browser I get the following error:
> docuvieware-min.js:166 Uncaught TypeError: Cannot read property 'parse' of undefined
at eval (docuvieware-min.js:166)
at eval (docuvieware-min.js:20)
at Object.eval (docuvieware-min.js:20)
at eval (docuvieware-min.js:1128)
at Object../src/docuvieware/docuvieware-min.js (main.bundle.js:208)
at __webpack_require__ (inline.bundle.js:55)
at eval (docuvieware.js:1)
at Object../src/app/ponents/detalleExpediente/docuvieware.js (main.bundle.js:128)
at __webpack_require__ (inline.bundle.js:55)
at eval (detalleExpedienteponent.ts:7)
So, if I ment the require line the error disappears but I need it. Any idea why I get this error? Thanks in advance for the help.
I'm using angular 5, I'm trying to use a javascript file that hold some methods that use a library from docuvieware. I ended up using javascript since I was unable to use it on typescript. So I have the following code:
const { docuVieware } = require('../../../docuvieware/docuvieware-min');
module.exports = { loadFile:
function loadFile(file) {
if (file != null) {
var params = {
Value: file,
Example: false
};
docuVieware.DocuViewareAPI.PostCustomServerAction("DocuVieware1",
true, "loadFile", params, function(result){ console.log("result: " +
JSON.stringify(result)); });
}
}
};
But whenever I open my browser I get the following error:
> docuvieware-min.js:166 Uncaught TypeError: Cannot read property 'parse' of undefined
at eval (docuvieware-min.js:166)
at eval (docuvieware-min.js:20)
at Object.eval (docuvieware-min.js:20)
at eval (docuvieware-min.js:1128)
at Object../src/docuvieware/docuvieware-min.js (main.bundle.js:208)
at __webpack_require__ (inline.bundle.js:55)
at eval (docuvieware.js:1)
at Object../src/app/ponents/detalleExpediente/docuvieware.js (main.bundle.js:128)
at __webpack_require__ (inline.bundle.js:55)
at eval (detalleExpediente.ponent.ts:7)
So, if I ment the require line the error disappears but I need it. Any idea why I get this error? Thanks in advance for the help.
Share Improve this question asked May 24, 2018 at 14:34 Alex VarelaAlex Varela 2172 gold badges4 silver badges14 bronze badges 4-
I would guess that there is either a bug in
docuVieware
(whatever that is) or your using it wrong. – Liam Commented May 24, 2018 at 14:44 - Yeah, I can see that, I have it declared in my angular-cli.json, since using it in the index doesn't work. But when I try to access it from a ts ponent to make use of its properties, I can't do it. The only way it works is inserting my functions in a script tag in the index.html – Alex Varela Commented May 24, 2018 at 14:50
- So since I can't access it in ts, I'm trying to make my own javascript repo with all the methods that I need. Thanks for the help btw. – Alex Varela Commented May 24, 2018 at 14:51
- Because I need to send some parameters from typescript to those methods, and it bees a mess if I do that. – Alex Varela Commented May 24, 2018 at 15:11
1 Answer
Reset to default 3You get this error because in the file docuvieware-min.js
, at the line 166
, the eval
function isn't able to read the property parse
of an object that doesn't contain it.
More concise : Javascript expects
object = {
parse: function() {...}
};
And you provide
object = undefined;
That's what you can expect when you try to import minified files into your non-minified project.
To use it in typescript, you need to import the definitions file. If you don't know how to, you need to declare your file as a script in your angular-cli.json
file. Once it's done, the object will be declared as global, hence giving you the right to use it with
declare var docuVieware: any;
docuVieware.DocuViewareAPI.PostCustomServerAction(...)