theme and mode path infer issue with ace.js and Angular - javascript

Sorry, the question unfortunately hasn't got much detail as I am not sure what exactly is required to explain the issue. To start with, I am trying to use ng2-ace-editor in my Angular application. My setup is not standard though. Details are in this other related problem - application can't find a .js file
In summary, if I explicitly include ace.js in my top level html then things work. But I don't want to do that as I want to use only the bundles created by Angular. But if I use only the bundles then I get the following error when I run the application -
ace.js:1 Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes or with webpack use ace/webpack-resolver
f # ace.js:1
t.loadModule # ace.js:1
setTheme # ace.js:1
setTheme # ace.js:1
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.setTheme # component.js:117
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.init # component.js:48
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.ngOnInit # component.js:40
checkAndUpdateDirectiveInline # core.js:9250
checkAndUpdateNodeInline # core.js:10514
checkAndUpdateNode # core.js:10476
debugCheckAndUpdateNode # core.js:11109
debugCheckDirectivesFn # core.js:11069
eval # NewPracticeQuestionComponent.html:188
debugUpdateDirectives # core.js:11061
checkAndUpdateView # core.js:10458
callViewAction # core.js:10699
execComponentViewsAction # core.js:10641
checkAndUpdateView # core.js:10464
callViewAction # core.js:10699
execEmbeddedViewsAction # core.js:10662
checkAndUpdateView # core.js:10459
callViewAction # core.js:10699
execComponentViewsAction # core.js:10641
checkAndUpdateView # core.js:10464
callViewAction # core.js:10699
execComponentViewsAction # core.js:10641
checkAndUpdateView # core.js:10464
callWithDebugContext # core.js:11351
debugCheckAndUpdateView # core.js:11029
push../node_modules/#angular/core/fesm5/core.js.ViewRef_.detectChanges # core.js:8845
(anonymous) # core.js:4581
push../node_modules/#angular/core/fesm5/core.js.ApplicationRef.tick # core.js:4581
(anonymous) # core.js:4473
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke # zone.js:388
onInvoke # core.js:3824
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke # zone.js:387
push../node_modules/zone.js/dist/zone.js.Zone.run # zone.js:138
push../node_modules/#angular/core/fesm5/core.js.NgZone.run # core.js:3738
next # core.js:4473
schedulerFn # core.js:3555
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub # Subscriber.js:209
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next # Subscriber.js:147
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next # Subscriber.js:80
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next # Subscriber.js:55
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next # Subject.js:47
push../node_modules/#angular/core/fesm5/core.js.EventEmitter.emit # core.js:3539
checkStable # core.js:3793
onHasTask # core.js:3837
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.hasTask # zone.js:441
push../node_modules/zone.js/dist/zone.js.ZoneDelegate._updateTaskCount # zone.js:461
push../node_modules/zone.js/dist/zone.js.Zone._updateTaskCount # zone.js:285
push../node_modules/zone.js/dist/zone.js.Zone.runTask # zone.js:205
drainMicroTaskQueue # zone.js:595
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask # zone.js:500
invokeTask # zone.js:1540
globalZoneAwareCallback # zone.js:1566
Show 26 more frames
ace.js:1 GET http://localhost:9000/theme-monokai.js net::ERR_ABORTED 404 (Not Found)
t.loadScript # ace.js:1
t.loadModule # ace.js:1
setTheme # ace.js:1
setTheme # ace.js:1
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.setTheme # component.js:117
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.init # component.js:48
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.ngOnInit # component.js:40
checkAndUpdateDirectiveInline # core.js:9250
checkAndUpdateNodeInline # core.js:10514
checkAndUpdateNode # core.js:10476
debugCheckAndUpdateNode # core.js:11109
debugCheckDirectivesFn # core.js:11069
eval # NewPracticeQuestionComponent.html:188
debugUpdateDirectives # core.js:11061
checkAndUpdateView # core.js:10458
callViewAction # core.js:10699
execComponentViewsAction # core.js:10641
checkAndUpdateView # core.js:10464
callViewAction # core.js:10699
execEmbeddedViewsAction # core.js:10662
checkAndUpdateView # core.js:10459
callViewAction # core.js:10699
execComponentViewsAction # core.js:10641
checkAndUpdateView # core.js:10464
callViewAction # core.js:10699
execComponentViewsAction # core.js:10641
checkAndUpdateView # core.js:10464
callWithDebugContext # core.js:11351
debugCheckAndUpdateView # core.js:11029
push../node_modules/#angular/core/fesm5/core.js.ViewRef_.detectChanges # core.js:8845
(anonymous) # core.js:4581
push../node_modules/#angular/core/fesm5/core.js.ApplicationRef.tick # core.js:4581
(anonymous) # core.js:4473
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke # zone.js:388
onInvoke # core.js:3824
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke # zone.js:387
push../node_modules/zone.js/dist/zone.js.Zone.run # zone.js:138
push../node_modules/#angular/core/fesm5/core.js.NgZone.run # core.js:3738
next # core.js:4473
schedulerFn # core.js:3555
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub # Subscriber.js:209
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next # Subscriber.js:147
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next # Subscriber.js:80
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next # Subscriber.js:55
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next # Subject.js:47
push../node_modules/#angular/core/fesm5/core.js.EventEmitter.emit # core.js:3539
checkStable # core.js:3793
onHasTask # core.js:3837
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.hasTask # zone.js:441
push../node_modules/zone.js/dist/zone.js.ZoneDelegate._updateTaskCount # zone.js:461
push../node_modules/zone.js/dist/zone.js.Zone._updateTaskCount # zone.js:285
push../node_modules/zone.js/dist/zone.js.Zone.runTask # zone.js:205
drainMicroTaskQueue # zone.js:595
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask # zone.js:500
invokeTask # zone.js:1540
globalZoneAwareCallback # zone.js:1566
Show 26 more frames
414ede0a-7ac6-4556-a68b-bfcd8c991283:1 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:9000/worker-javascript.js' failed to load.
at blob:http://localhost:9000/414ede0a-7ac6-4556-a68b-bfcd8c991283:1:1
Further analysis shows that the error is thrown from the following piece of code in ace.js.
exports.loadModule = function(moduleName, onLoad) {
var module, moduleType;
if (Array.isArray(moduleName)) {
moduleType = moduleName[0];
moduleName = moduleName[1];
}
try {
module = require(moduleName);
} catch (e) {}
if (module && !exports.$loading[moduleName])
return onLoad && onLoad(module);
if (!exports.$loading[moduleName])
exports.$loading[moduleName] = [];
exports.$loading[moduleName].push(onLoad);
if (exports.$loading[moduleName].length > 1)
return;
var afterLoad = function() {
require([moduleName], function(module) {
exports._emit("load.module", {name: moduleName, module: module});
var listeners = exports.$loading[moduleName];
exports.$loading[moduleName] = null;
listeners.forEach(function(onLoad) {
onLoad && onLoad(module);
});
});
};
if (!exports.get("packaged"))
return afterLoad();
net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
reportErrorIfPathIsNotConfigured();
};
var reportErrorIfPathIsNotConfigured = function() {
if (
!options.basePath && !options.workerPath
&& !options.modePath && !options.themePath
&& !Object.keys(options.$moduleUrls).length
) {
console.error(
"Unable to infer path to ace from script src,",
"use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes",
"or with webpack use ace/webpack-resolver"
);
reportErrorIfPathIsNotConfigured = function() {};
}
};
What is causing the issue? I suppose Angular uses webpack. What is this ace/webpack-resolver thing? How do I solve the issue?

I finally was able to make my code work. My setup is different.
The reason adding script tag explicitly made my code work is because By default ace detcts the url for dynamic loading by finding the script node for ace.js. This doesn't work if ace.js is not loaded with a separate script tag, and in this case it is required to set url explicitely (https://ace.c9.io/#nav=howto). As I am loading modes and themes without using script, I had to use basePath etc. (see answer further).
I build my Angular application and the it is served from my Play server. The angular build is stored in Play's /public/ui folder. The requests should be in format /assets/ui/.. which gets mapped to /public/ui/... due to a rule in Play routes file
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
When I ran the code, I got error.
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:9000/worker-javascript.js' failed to load.
at blob:http://localhost:9000/3df21e42-fecb-4026-8bd6-f2b0d1d0540a:1:1
Earlier, I also got error `Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes or with webpack use ace/webpack-resolver`
It seems ng-ace-editor imports .js scripts (theme, mode, worker) based on the theme and mode of the editor. The theme and mode .js files can be included in scripts.js but some worker-.js files can't be (I don't know why, maybe because worker ones are loaded dynamically using importScript).
The scripts section in Angular.json is (this will all get bundled in scripts.js in Angular's final bundle)
"scripts": [
"./node_modules/ace-builds/src/ace.js",
"./node_modules/ace-builds/src/theme-eclipse.js",
"./node_modules/ace-builds/src/theme-monokai.js",
"./node_modules/ace-builds/src/mode-html.js"
]]
To include worker-.js files, I added this rule because it seems angular-cli can't load from node_modules. So I had to copy the files from node modules to root of my ui build - How to include assets from node_modules in angular cli project
"assets": [
"src/assets",
"src/favicon.ico",
{
"glob": "**/*",
"input": "./node_modules/ace-builds/src/",
"output": "/"
}
],
When I executed the code, I found error that http://localhost:9000/worker-javascript.js can't be loaded. I realised that my files are loaded in /assets/ui/ path and not in the server's root directory. So I set ace.js's basepath to /assets/ui in the component's .ts file
import * as ace from 'ace-builds/src-noconflict/ace';
ace.config.set('basePath', '/assets/ui/');
ace.config.set('modePath', '');
ace.config.set('themePath', '');
In summary basePath seem to be what is used to load scripts dynamically (eg worker scripts). modePath and themePath are / as the mode and theme scripts are bundled in scripts.js and my index.html correctly loaded scripts.js using <script> tag and are available at root level need to copy worker-.js files outside node_modules as angular_cli can't copy assets from node_modules

Related

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. How to find the location?

My nuxt.js project shows this issue:
[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.
warn # vue.runtime.esm.js?2b0e:619
patch # vue.runtime.esm.js?2b0e:6497
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
init # vue.runtime.esm.js?2b0e:3118
hydrate # vue.runtime.esm.js?2b0e:6378
patch # vue.runtime.esm.js?2b0e:6493
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
init # vue.runtime.esm.js?2b0e:3118
hydrate # vue.runtime.esm.js?2b0e:6378
hydrate # vue.runtime.esm.js?2b0e:6411
patch # vue.runtime.esm.js?2b0e:6493
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
init # vue.runtime.esm.js?2b0e:3118
hydrate # vue.runtime.esm.js?2b0e:6378
hydrate # vue.runtime.esm.js?2b0e:6411
patch # vue.runtime.esm.js?2b0e:6493
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
init # vue.runtime.esm.js?2b0e:3118
hydrate # vue.runtime.esm.js?2b0e:6378
hydrate # vue.runtime.esm.js?2b0e:6411
patch # vue.runtime.esm.js?2b0e:6493
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
init # vue.runtime.esm.js?2b0e:3118
hydrate # vue.runtime.esm.js?2b0e:6378
hydrate # vue.runtime.esm.js?2b0e:6411
patch # vue.runtime.esm.js?2b0e:6493
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
init # vue.runtime.esm.js?2b0e:3118
hydrate # vue.runtime.esm.js?2b0e:6378
hydrate # vue.runtime.esm.js?2b0e:6411
patch # vue.runtime.esm.js?2b0e:6493
Vue._update # vue.runtime.esm.js?2b0e:3945
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4479
Watcher # vue.runtime.esm.js?2b0e:4468
mountComponent # vue.runtime.esm.js?2b0e:4073
Vue.$mount # vue.runtime.esm.js?2b0e:8415
mount # client.js?06a0:709
_callee5$ # client.js?06a0:747
tryCatch # runtime.js?96cf:45
invoke # runtime.js?96cf:274
prototype.<computed> # runtime.js?96cf:97
asyncGeneratorStep # asyncToGenerator.js?1da1:3
_next # asyncToGenerator.js?1da1:25
Promise.then (async)
asyncGeneratorStep # asyncToGenerator.js?1da1:13
_next # asyncToGenerator.js?1da1:25
Promise.then (async)
asyncGeneratorStep # asyncToGenerator.js?1da1:13
_next # asyncToGenerator.js?1da1:25
eval # asyncToGenerator.js?1da1:32
eval # asyncToGenerator.js?1da1:21
_mountApp # client.js?06a0:693
mountApp # client.js?06a0:693
Promise.then (async)
eval # client.js?06a0:96
eval # client.js:1169
./.nuxt/client.js # app.js:35
__webpack_require__ # runtime.js:854
fn # runtime.js:151
0 # app.js:861
__webpack_require__ # runtime.js:854
checkDeferredModules # runtime.js:46
webpackJsonpCallback # runtime.js:33
(anonymous) # app.js:1
I know the meaning of the issue, but how can I locate the place?
it seems do not give the wrong code location information.
EDIT-01
In my layout/default.vue, after I added the <Header/> , it caused the issue.
<template>
<div>
<Header></Header>
<nuxt/>
</div>
</template>
My Header is like this structure:
<template>
<div class="main-body" >...</div>
</template>

How to resolve "Animated: `useNativeDriver` is not supported because the native animated module is missing." in react-navigation?

I am working on expo SDK Version: 36, and on all platforms (ios/android/web)
When installing react-navigation for the first time as described in the documentation and running jest --watch while doing it, and the following warning appeared:
console.warn node_modules/react-native/Libraries/YellowBox/YellowBox.js:71
Animated: `useNativeDriver` is not supported because the native animated module is missing. Falling back to JS-based animation. To resolve this, add `RCTAnimation` module to this app, or remove `useNativeDriver`. More info: https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
It also happen in the browser console:
bundle.js:18272 Animated: `useNativeDriver` is not supported because the native animated module is missing. Falling back to JS-based animation. To resolve this, add `RCTAnimation` module to this app, or remove `useNativeDriver`. More info: https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
in Card (at CardContainer.tsx:132)
in CardContainer (at CardStack.tsx:499)
in CardStack (at StackView.tsx:384)
in KeyboardManager (at StackView.tsx:382)
in Context.Consumer (at StackView.tsx:380)
in StackView (at StackView.tsx:41)
in StackView (at createStackNavigator.tsx:33)
in Anonymous (at createNavigator.js:80)
in Navigator (at createAppContainer.js:351)
in NavigationContainer (at AppCore.js:15)
in AppCore (at App.js:14)
in App (at withExpoRoot.web.js:13)
in ExpoRootComponent (at registerRootComponent.web.js:6)
in RootComponent
warn # bundle.js:18272
r # backend.js:6
shouldUseNativeDriver # bundle.js:76326
TimingAnimation # bundle.js:76894
start # bundle.js:75709
start # bundle.js:75715
Card._this.animate # bundle.js:85843
componentDidMount # bundle.js:85980
commitLifeCycles # bundle.js:52243
commitLayoutEffects # bundle.js:55486
callCallback # bundle.js:30478
invokeGuardedCallbackDev # bundle.js:30527
invokeGuardedCallback # bundle.js:30582
commitRootImpl # bundle.js:55224
unstable_runWithPriority # bundle.js:92068
runWithPriority$2 # bundle.js:42291
commitRoot # bundle.js:55064
finishSyncRender # bundle.js:54471
performSyncWorkOnRoot # bundle.js:54449
(anonymous) # bundle.js:42341
unstable_runWithPriority # bundle.js:92068
runWithPriority$2 # bundle.js:42291
flushSyncCallbackQueueImpl # bundle.js:42336
flushSyncCallbackQueue # bundle.js:42324
scheduleUpdateOnFiber # bundle.js:53851
enqueueSetState # bundle.js:44136
../../../react/cjs/react.development.js.Component.setState # bundle.js:88125
_callee2$ # bundle.js:1353
tryCatch # bundle.js:90193
invoke # bundle.js:90419
prototype.<computed> # bundle.js:90245
tryCatch # bundle.js:90193
invoke # bundle.js:90283
(anonymous) # bundle.js:90293
Promise.then (async)
invoke # bundle.js:90292
(anonymous) # bundle.js:90293
Promise.then (async)
invoke # bundle.js:90292
(anonymous) # bundle.js:90318
callInvokeWithMethodAndArg # bundle.js:90317
enqueue # bundle.js:90340
prototype.<computed> # bundle.js:90245
../../../regenerator-runtime/runtime.js.exports.async # bundle.js:90364
_callee2 # bundle.js:1324
SplashScreen # bundle.js:1537
constructClassInstance # bundle.js:44346
updateClassComponent # bundle.js:48555
beginWork$1 # bundle.js:50328
beginWork$$1 # bundle.js:55898
performUnitOfWork # bundle.js:54837
workLoopSync # bundle.js:54813
performSyncWorkOnRoot # bundle.js:54412
(anonymous) # bundle.js:42341
unstable_runWithPriority # bundle.js:92068
runWithPriority$2 # bundle.js:42291
flushSyncCallbackQueueImpl # bundle.js:42336
flushSyncCallbackQueue # bundle.js:42324
scheduleUpdateOnFiber # bundle.js:53851
enqueueSetState # bundle.js:44136
../../../react/cjs/react.development.js.Component.setState # bundle.js:88125
onFinish # bundle.js:1392
_callee$ # bundle.js:18446
tryCatch # bundle.js:90193
invoke # bundle.js:90419
prototype.<computed> # bundle.js:90245
tryCatch # bundle.js:90193
invoke # bundle.js:90283
(anonymous) # bundle.js:90293
Promise.then (async)
invoke # bundle.js:90292
(anonymous) # bundle.js:90318
callInvokeWithMethodAndArg # bundle.js:90317
enqueue # bundle.js:90340
prototype.<computed> # bundle.js:90245
../../../regenerator-runtime/runtime.js.exports.async # bundle.js:90364
_callee # bundle.js:18389
componentDidMount # bundle.js:18470
commitLifeCycles # bundle.js:52243
commitLayoutEffects # bundle.js:55486
callCallback # bundle.js:30478
invokeGuardedCallbackDev # bundle.js:30527
invokeGuardedCallback # bundle.js:30582
commitRootImpl # bundle.js:55224
unstable_runWithPriority # bundle.js:92068
runWithPriority$2 # bundle.js:42291
commitRoot # bundle.js:55064
finishSyncRender # bundle.js:54471
performSyncWorkOnRoot # bundle.js:54449
scheduleUpdateOnFiber # bundle.js:53840
updateContainer # bundle.js:57245
(anonymous) # bundle.js:57670
unbatchedUpdates # bundle.js:54575
legacyRenderSubtreeIntoContainer # bundle.js:57669
render # bundle.js:57750
renderApplication # bundle.js:65334
run # bundle.js:65227
runApplication # bundle.js:65266
registerRootComponent # bundle.js:18777
../../../expo/AppEntry.js # bundle.js:14474
__webpack_require__ # bundle.js:727
fn # index.js:69
0 # bundle.js:101987
__webpack_require__ # bundle.js:727
(anonymous) # bundle.js:794
(anonymous) # bundle.js:797
Show 40 more frames
[Violation] 'requestAnimationFrame'
Related issues:
https://github.com/expo/ex-navigation/issues/276
https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
The last one offers a solution, but it says to open Xcode, while I am on Linux Debian 10. I do not have Xcode. I can use a Macbook and do the step but I am wondering:
Should I care when working on Linux?
Should I care when working on Macbook (if it happens)?
Should I care for the health of my app while testing? Under which circumstances?
To disable this warning add either of the following to your test file.
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
or
jest.mock('NativeAnimatedHelp');
In your package.json file
"jest": {
"setupFiles": [
"./mock.js"
],
In mock.js
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('NativeAnimatedHelp');
You can safely ignore this warning. useNativeDriver is only important when running the code on device.
Nothing above wasn't working for me, but eventually I've found solution here:
create jest-setup.js file (in my case in src/tests directory):
src/tests/jest-setup.js:
import 'react-native-gesture-handler/jestSetup';
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
jest.mock('react-native-reanimated', () => {
const Reanimated = require('react-native-reanimated/mock');
// The mock for `call` immediately calls the callback which is incorrect
// So we override it with a no-op
Reanimated.default.call = () => {};
return Reanimated;
});
Install necessary packages (in my case react-native-reanimated only, but maybe your code will ask you something else):
npm install --save-dev react-native-reanimated
Add one row to jest config in package.json:
"jest": {
"setupFiles": [
"<rootDir>/src/tests/jest-setup.js"
]
},
If your jest-setup.js file located in other directory - change location accordingly.
After these simple steps, the annoying warning has gone. Thanks Spencer Carli and his article by link above.

Vue Socket.io-Extended this.$socket.$subscribe is not a function" after switching router pages

I have setup a simple Vue App that should connect to a nodeJS Server with Websockets.
I'm using socket.io-extended.
i have inserted the websocket connection into a component using the documentation. When refreshing the page the connection works without problems. However, when I use vue router to switch the page and then back to the websocket page, I get the following console message:
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in mounted hook: "TypeError: this.$socket.$subscribe is not a function"
found in
---> <Index> at src/components/Client/LiveDataDrink/Index.vue
<VContent>
<VApp>
<App> at src/App.vue
<Root>
warn # vue.runtime.esm.js?2b0e:619
logError # vue.runtime.esm.js?2b0e:1884
globalHandleError # vue.runtime.esm.js?2b0e:1879
handleError # vue.runtime.esm.js?2b0e:1839
invokeWithErrorHandling # vue.runtime.esm.js?2b0e:1862
callHook # vue.runtime.esm.js?2b0e:4213
insert # vue.runtime.esm.js?2b0e:3139
invokeInsertHook # vue.runtime.esm.js?2b0e:6340
patch # vue.runtime.esm.js?2b0e:6559
Vue._update # vue.runtime.esm.js?2b0e:3942
updateComponent # vue.runtime.esm.js?2b0e:4060
get # vue.runtime.esm.js?2b0e:4473
run # vue.runtime.esm.js?2b0e:4548
flushSchedulerQueue # vue.runtime.esm.js?2b0e:4304
eval # vue.runtime.esm.js?2b0e:1980
flushCallbacks # vue.runtime.esm.js?2b0e:1906
Promise.then (async)
timerFunc # vue.runtime.esm.js?2b0e:1933
nextTick # vue.runtime.esm.js?2b0e:1990
queueWatcher # vue.runtime.esm.js?2b0e:4396
update # vue.runtime.esm.js?2b0e:4538
notify # vue.runtime.esm.js?2b0e:730
reactiveSetter # vue.runtime.esm.js?2b0e:1055
eval # vue-router.esm.js?8c4f:2748
eval # vue-router.esm.js?8c4f:2747
updateRoute # vue-router.esm.js?8c4f:2174
eval # vue-router.esm.js?8c4f:2037
eval # vue-router.esm.js?8c4f:2159
step # vue-router.esm.js?8c4f:1843
step # vue-router.esm.js?8c4f:1850
runQueue # vue-router.esm.js?8c4f:1854
eval # vue-router.esm.js?8c4f:2154
step # vue-router.esm.js?8c4f:1843
eval # vue-router.esm.js?8c4f:1847
eval # vue-router.esm.js?8c4f:2139
eval # vue-router.esm.js?8c4f:1921
iterator # vue-router.esm.js?8c4f:2120
step # vue-router.esm.js?8c4f:1846
step # vue-router.esm.js?8c4f:1850
step # vue-router.esm.js?8c4f:1850
runQueue # vue-router.esm.js?8c4f:1854
confirmTransition # vue-router.esm.js?8c4f:2147
transitionTo # vue-router.esm.js?8c4f:2034
push # vue-router.esm.js?8c4f:2365
push # vue-router.esm.js?8c4f:2782
handler # vue-router.esm.js?8c4f:1066
invokeWithErrorHandling # vue.runtime.esm.js?2b0e:1854
invoker # vue.runtime.esm.js?2b0e:2179
original._wrapper # vue.runtime.esm.js?2b0e:6911
Show 18 more frames
vue.runtime.esm.js?2b0e:1888 TypeError: this.$socket.$subscribe is not a function
at VueComponent.mounted (Index.vue?b484:23)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at callHook (vue.runtime.esm.js?2b0e:4213)
at Object.insert (vue.runtime.esm.js?2b0e:3139)
at invokeInsertHook (vue.runtime.esm.js?2b0e:6340)
at VueComponent.patch [as __patch__] (vue.runtime.esm.js?2b0e:6559)
at VueComponent.Vue._update (vue.runtime.esm.js?2b0e:3942)
at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4060)
at Watcher.get (vue.runtime.esm.js?2b0e:4473)
at Watcher.run (vue.runtime.esm.js?2b0e:4548)
this works with me for Dynamic Listener:
this.sockets.subscribe('EVENT_NAME', (data) => {
this.msg = data.message;
});
this.sockets.unsubscribe('EVENT_NAME');

Cannot import Jimp into Angular 6 for image processing

I would like to use jimp with angular 6 to resize images from a base64 source before uploading them to the server. I tried to import it like this:
import * as Jimp from 'jimp';
which ended in a missing resource because only the browser code is loaded. Then I tried to load the jimp code itselft like this:
import {Jimp} from 'jimp/index';
which ended up in a lot of errors
Errors while compiling. Reload prevented.
errors # client?c480:161
onmessage # socket.js:41
EventTarget.dispatchEvent # sockjs.js:170
(anonymous) # sockjs.js:883
SockJS._transportMessage # sockjs.js:881
EventEmitter.emit # sockjs.js:86
WebSocketTransport.ws.onmessage # sockjs.js:2957
wrapFn # zone.js:1188
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask # zone.js:421
push../node_modules/zone.js/dist/zone.js.Zone.runTask # zone.js:188
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask # zone.js:496
invokeTask # zone.js:1540
globalZoneAwareCallback # zone.js:1566
client?c480:167 ./node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\myProject\node_modules\aws4'
errors # client?c480:167
onmessage # socket.js:41
EventTarget.dispatchEvent # sockjs.js:170
(anonymous) # sockjs.js:883
SockJS._transportMessage # sockjs.js:881
EventEmitter.emit # sockjs.js:86
WebSocketTransport.ws.onmessage # sockjs.js:2957
wrapFn # zone.js:1188
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask # zone.js:421
push../node_modules/zone.js/dist/zone.js.Zone.runTask # zone.js:188
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask # zone.js:496
invokeTask # zone.js:1540
globalZoneAwareCallback # zone.js:1566
client?c480:167 ./node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\myProject\node_modules\ecc-jsbn'
errors # client?c480:167
onmessage # socket.js:41
EventTarget.dispatchEvent # sockjs.js:170
(anonymous) # sockjs.js:883
SockJS._transportMessage # sockjs.js:881
EventEmitter.emit # sockjs.js:86
WebSocketTransport.ws.onmessage # sockjs.js:2957
wrapFn # zone.js:1188
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask # zone.js:421
push../node_modules/zone.js/dist/zone.js.Zone.runTask # zone.js:188
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask # zone.js:496
invokeTask # zone.js:1540
globalZoneAwareCallback # zone.js:1566
client?c480:167 ./node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:\Users\myProject\node_modules\oauth-sign'
...
I would also use an alternative library, but I only found jimp for pure JS image processing.
A solution was posted in it issue list on github, but it did not work for me.
I think you'll not load it cause it'a lib for NodeJS so it's for 'back end' purpose .. you can't do it in front end in that way.
If you want to do in your Angular Front end .. i think you've to try to work on the CANVAS
maybe you can try something like this package:
`https://www.npmjs.com/package/re`size-base64

angular2 + typescript: is it possible to configure compiler to include my source code line in error stacktrace?

in Angular 2 project written in typescript and packaged with webpack I add e.g. following throw to welcome.ts file:
#Page({
templateUrl: 'build/views/welcome/welcome.html'
})
export class Welcome{
constructor(){
throw('something went wrong')
}
}
In JS console, I see following error and stacktrace:
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error during instantiation of Welcome!.
ORIGINAL EXCEPTION: something went wrong
ERROR CONTEXT:
[object Object]BrowserDomAdapter.logError # browser_adapter.js?f9d6:77
BrowserDomAdapter.logGroup # browser_adapter.js?f9d6:87
ExceptionHandler.call # exception_handler.js?1ee2:57
(anonymous function) # application_ref.js?7cf8:194
EventEmitter.subscribe.schedulerFn # async.js?563f:123
SafeSubscriber.__tryOrUnsub # VM2136:166SafeSubscriber.next # VM2136:115
Subscriber._next # VM2136:74Subscriber.next # VM2136:51
Subject._finalNext # VM2130:124Subject._next # VM2130:116
Subject.next # VM2130:73EventEmitter.emit # async.js?563f:112
_a._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError # ng_zone.js?c886:120
_a.inner.inner.fork.onHandleError # ng_zone_impl.js?4233:66
ZoneDelegate.handleError # zone.js?fad3:327Zone.runGuarded # zone.js?fad3:233
_loop_1 # zone.js?fad3:487drainMicroTaskQueue # zone.js?fad3:494cancelFn.invoke # zone.js?fad3:426
browser_adapter.js?f9d6:77
STACKTRACE:BrowserDomAdapter.logError # browser_adapter.js?f9d6:77
ExceptionHandler.call # exception_handler.js?1ee2:59
(anonymous function) # application_ref.js?7cf8:194
EventEmitter.subscribe.schedulerFn # async.js?563f:123
SafeSubscriber.__tryOrUnsub # VM2136:166SafeSubscriber.next # VM2136:115
Subscriber._next # VM2136:74
Subscriber.next # VM2136:51
Subject._finalNext # VM2130:124
Subject._next # VM2130:116
Subject.next # VM2130:73
EventEmitter.emit # async.js?563f:112
_a._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError # ng_zone.js?c886:120_
a.inner.inner.fork.onHandleError # ng_zone_impl.js?4233:66
ZoneDelegate.handleError # zone.js?fad3:327
Zone.runGuarded # zone.js?fad3:233
_loop_1 # zone.js?fad3:487drainMicroTaskQueue # zone.js?fad3:494
cancelFn.invoke # zone.js?fad3:426
Is it possible to configure typescript compiler and webpack so that the stacktrace will also feature my welcome.ts file? e.g.:
constructor # welcome.ts:7
So far I tried all the options in webpack devtool option and in tsconfig.js compilerOptions.sourceMap is set to true, but none helped.

Categories