How can I replace the bower package jsTimezoneDetect in npm - angularjs

I am trying to replace bower in my repo and I am having trouble replacing this package: "jsTimezoneDetect": "1.0.4". The suggested package to replace this is "jstimezonedetect": "^1.0.6". I am using this package as shown here:
var missionJoin = {
timeZoneId : jstz.determine().name()
};
This however, gives me this error:
ReferenceError: Can't find variable: Intl in node_modules/jstimezonedetect/dist/jstz.js (line 124)
get_from_internationalization_api#node_modules/jstimezonedetect/dist/jstz.js:124:22
determine#node_modules/jstimezonedetect/dist/jstz.js:412:67
joinMission#app/scripts/controllers/robo.profile.ProfileServiceCtrl.js:1:27975
test/specs/robo.profile.profileServiceCtrl.spec.js:151:27
<Jasmine>
This package does not have any dependencies and the error seems to come from a problem in the package itself. Is there something I am doing wrong here? Has anyone else faced a similar issue? Any help would be greatly appreciated!

For anyone who might face this problem in the future, here is how I got around this issue:
Found in the last paragraph of https://github.com/iansinnott/jstz
export function findTimeZone() {
const oldIntl = window.Intl
try {
window.Intl = undefined
const tz = jstz.determine().name()
window.Intl = oldIntl
return tz
} catch (e) {
// sometimes (on android) you can't override intl
return jstz.determine().name()
}
}
and
var missionJoin = {
timeZoneId : findTimeZone()
};

Related

How to resolve #typescript-eslint/no-var-requires error. Error while adding #axe-core/react

I have added axe-core/react into my project by:
npm install --save-dev #axe-core/react
Now I have added the following piece of code in my index.tsx to get it up and running:
if (process.env.NODE_ENV !== 'production') {
const axe = require('#axe-core/react');
axe(React, ReactDOM, 1000);
}
Now if I navigate to localhost, the page shows a compile error with the following message:
src\index.tsx
Line 14:17: Require statement not part of import statement
#typescript-eslint/no-var-requires
This error is happening for line:
const axe = require('#axe-core/react');
How do I import it otherwise?
PS: I tried doing something like:
import foo = require("foo")
But still no luck.
Replacing the line
const axe = require('#axe-core/react');
With
import axe from '#axe-core/react';
resolved my issue.

React class component setting state, getting parsing error for the "=" sign

I am using create-react-app (unejected) with this code:
class App extends Component {
state = {
path: 'some_string',
organization: null,
errors: null
}
componentDidMount() {
this.onFetchFromGitHub(this.state.path);
};
...
The code (the application) works as expected.
However I am getting an error in vscode:
Parsing error: unexpected token = eslint [134,9]
That is the "=" in:
state = {`
/|\
|
which is highlight in vscode.
My understanding is that I can use this format instead of a constructor with bindings.
As I said the app is working despite the error.
.eslintrc.yml
Which version of React are you using?
React introduced "hooks" in 16.8, and they largely replace the old "Component" class format.
See the introduction here: https://reactjs.org/docs/hooks-intro.html
Using hooks, your example above can be simplified to a function component:
const App = (props) => {
// This replaces the this.state/this.setState from a component
const [state, setState] = React.useState({
path: 'some_string',
organization: null,
errors: null
});
// This replaces the on mount
React.useEffect(() => {
onFetchFromGitHub(state.path);
}, []);
return ...
}
As for why your example does not work, I would suggest it is likely due to configuration of your IDE syntax highlighting. Check whether you have the right syntax plugins installed/active (es2015, react, etc.) and if your linter (if you have one) has the correct plugins and presets. Your code works fine in my IDE, with no errors.
I fixed this by installing eslint. This gave a problem due to conflict with create-react-app so I had to pin package.json version of eslint to 6.6.0 and then delete package-lock.json and remove node_modules/ and then I got about 30 warnings (instead of one).
Finally I changed the source code to fix the unnecessary parens and ignore propType errors and finally I am error free.

Uncaught Error: undefined is not function (near '...(0,_resolveAssetSource2.setCustomTransformer))

Getting error after expo start for android
The issue is with expo-asset.
I removed this chunk of code from expo-asset/build/Asset.js from node_modules.
// Override React Native's asset resolution for `Image` components
setCustomSourceTransformer(resolver => {
try {
const asset = Asset.fromMetadata(resolver.asset);
return resolver.fromSource(asset.downloaded ? asset.localUri : asset.uri);
}
catch (e) {
return resolver.defaultAsset();
}
});
Not a great solution but it gets the app to run =(
I only started getting this error after upgrading to Expo SDK 33.

Error: Cannot find module 'react/lib/Object.assign' from dispatcher

Below is my dispatcher code
var Dispatcher = require("flux").Dispatcher;
var assign = require("react/lib/Object.assign");
var AppDispatcher = assign(new Dispatcher(), {
handleViewAction: function(action){
console.log('action', action)
this.dispatch({
source: 'VIEW_ACTION',
action: action
})
}
});
module.exports = AppDispatcher;
gulp is not starting it is throwing error
Error: Cannot find module 'react/lib/Object.assign' from '/Users/shanky-munjal/projects/testFlux/src/js/dispatchers'
at /Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
at process (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
at ondir (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
at load (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
at onex (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
at /Users/shankymunjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:82:15)
I am using react 15.2.1
use Object.assign
A long time ago Dan Abramov wrote:
This is a gentle reminder that require('react/lib/SomeInternalModule')
in your component will break in some release regardless of semver.
npm install object-assign --save
this code will work
var assign = require("react/lib/Object.assign");
this code instead of
var assign = require("Object-assign");

Wkhtmltopdf patched QT issue with angularjs

I get this JavaScript error when running any version of wkhtmltopdf with patched Qt:
Warning: undefined:0 Error: [$injector:modulerr] Failed to instantiate module ng due to:
'undefined' is not an object
http://errors.angularjs.org/1.5.7/$injector/modulerrp0=ng&p1='undefined'%20is%20not%20an%20object
(I'm trying to render a page with angularjs 1.5).
When I use a version of wkhtmltopdf without patched Qt I don't get the error and everything works fine.
I use this heroku buildpack which installs version 0.12.3 with patched Qt, and I got this error.
Any idea how to solve my problem? I may install wkhtmltopdf without patched Qt on production but it seems I will have to compile it...
I finally managed to make it work with all versions: I needed a special version of the .bind() JavaScript function polyfill:
var isFunction = function (o) {
return typeof o == 'function';
};
var bind,
slice = [].slice,
proto = Function.prototype,
featureMap;
featureMap = {
'function-bind': 'bind'
};
function has(feature) {
var prop = featureMap[feature];
return isFunction(proto[prop]);
}
// check for missing features
if (!has('function-bind')) {
// adapted from Mozilla Developer Network example at
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
bind = function bind(obj) {
var args = slice.call(arguments, 1),
self = this,
nop = function() {
},
bound = function() {
return self.apply(this instanceof nop ? this : (obj || {}), args.concat(slice.call(arguments)));
};
nop.prototype = this.prototype || {}; // Firefox cries sometimes if prototype is undefined
bound.prototype = new nop();
return bound;
};
proto.bind = bind;
}

Resources