JavaScript error when importing a package - javascript

getting the following error when importing netscape.javascript
importClass(netscape.javascript)
org.mozilla.javascript.EcmaError: ReferenceError: "netscape" is not defined.
Trying to use javascript within applet to get access to cookies.
Using the following as an example to import required package
http://www.java2s.com/Code/Java/JDK-6/UsingJavaObjectsinJavaScript.htm
http://docs.oracle.com/javase/tutorial/deployment/applet/invokingJavaScriptFromApplet.html

Found out by trial and error.
It seems we need to prefix with Packages
importPackage(Packages.netscape.javascript);

Related

Require module inside a WebWorker in React

i am trying to import an npm module inside my React Web Worker using const package = require('package-name').
But it gives me the following error :
Uncaught (in promise) ReferenceError: require is not defined
How can i use a module inside a worker, is there a native way or some way to bypass it?
I am using NodeJS v18.10.0, Webpack v5.73.0.
I think your question is related to
Client on Node.js: Uncaught ReferenceError: require is not defined
please look at it , you might solved your problem

I trying to use babel and react but I keep getting an error

I am trying to use babel and react but I keep getting this error "Uncaught Error: Module name "react" has not been loaded yet for context: _. Use require([])". I don't know what I'm doing wrong.
Picture of HTML file
Picture of Javascript File
All I had to do was to install requireJS

ReferenceError: JSENCRYPT_VERSION is not defined after JSEncrypt 3.0.0

I was using jsencrypt 3.0.0-rc.1 and updated to 3.0.0 just now. Now I am having a following error.
Uncaught ReferenceError: JSENCRYPT_VERSION is not defined.
Temporary Solution
: I could get rid of that error by replacing import JSEncrypt from 'jsencrypt' with import JSEncrypt from 'jsencrypt/bin/jsencrypt.min.js'
Found via GitHub
Question:
Is there any cleaner solution to this or just have to wait for good fix by the author?
Just update to the 3.0.1 and you are good to go. No more hacks needed.

How can I get Web Components to compile with TypeScript for IE11/Edge/Chrome/Firefox?

Having set up a web project to use TypeScript/WebPack I cannot get Google Chrome to run the result:
The error reads: "Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function."
I learned that a shim is required for transpiling to ES5, but I still can't get this to work. That's probably because I don't want to add a <script> element to the HTML but instead I want to import "../node_modules/#webcomponents/webcomponentsjs/webcomponents-bundle"; in my .ts files.
How can I get this to work without adding <script> elements to my HTML files?
I took my tsconfig.json and webpack.config.js files from this tutorial.
Here's the solution:
npm install #webcomponents/webcomponentsjs --save-dev
import "#webcomponents/webcomponentsjs/webcomponents-bundle";
import '#webcomponents/webcomponentsjs/custom-elements-es5-adapter.js';
...
As far as I can see, this runs smoothly on Chrome, Firefox, Edge and IE11.

Uncaught SyntaxError in jquery.d.ts file

I'm trying to transition my jQuery project into a Typescript project. However, when I include the jQuery typings from the DefinitelyTyped Github using this method:
///<reference path="../../typings/jquery.d.ts"/>
I get "Uncaught SyntaxError: Unexpected identifier" on line 27 of jquery.d.ts, shown below
declare module 'jquery' {
export = jQuery;
}
I've done a bunch of searching about this problem, but I can't seem to find any solutions to this problem. What am I doing wrong?
(I am using WebStorm as my IDE)
EDIT:
Ok, I followed some instructions below and installed the jQuery typings via the npm terminal. However, when I remove the ///reference import, I now get an error in Webstorm: TS2304 cannot find name '$'. However, the code compiles to js and can run in the browser fine. It's just annoying to have those errors in my console in Webstorm. Is there something I need to add to get Webstorm to recognize jQuery?
most recommended practice nowaday is instead of ///reference import, install separate type packages: https://www.npmjs.com/package/#types/jquery as devdependency. (and ensure you're using latest ts compiler supports this)

Categories

Resources