I have two files:
// roles.js
export function roles() {
return {"/": ["admin","user"]};
}
// router.config.js
import {roles} from '../src/pages/.umi/roles'
console.log(roles['/']);
It throws:
TypeError: Cannot read property '/' of undefined
See? It is undefined. how can I make it accessible?
One of your mistakes is you're importing a function.
You should use roles()['/'] to get value
The other problem about undefined, probably is that you're importing wrong path like they're commenting.
Here you have an example that it runs.
https://stackblitz.com/edit/js-5cquau
Related
My application was working fine, and it stopped after trying to get the documentation with swagger, i think it may be a dependency issue, but can't find it anywhere.
I keep getting the error
10:10:22 PM - Starting compilation in watch mode...
Error Cannot read property 'getSymbol' of undefined
I don't know where getSymbol is used, and the error doesn't seem to help much. Hope someone can help me fix this issue. The complete application code can be found at:
https://github.com/JSLearningCode/enderecosAlunosAPI
Any help is welcome.
EDIT:
Running in dev mode I got this output:
/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/typescript/lib/typescript.js:95877
throw e;
^
TypeError: Cannot read property 'getSymbol' of undefined
at Object.isArray (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/utils/ast-utils.js:6:25)
at getTypeReferenceAsString (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/utils/plugin-utils.js:12:21)
at Object.getTypeReferenceAsString (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/utils/plugin-utils.js:31:29)
at ControllerClassVisitor.createTypePropertyAssignment (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:51:44)
at ControllerClassVisitor.createDecoratorObjectLiteralExpr (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:38:18)
at ControllerClassVisitor.addDecoratorToNode (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:29:22)
at visitNode (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:16:29)
at visitNodes (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/typescript/lib/typescript.js:70998:48)
at Object.visitEachChild (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/typescript/lib/typescript.js:71266:355)
at visitNode (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:18:23)
error Command failed with exit code 1.
There was an issue related to the routing in the application. I had a parser inside the controller that was used for directing correct routes between a route "aluno" with first Param.
Once I had taken the route with no params and put it first at the controller, there was no need anymore for the parser, and the issue was gone. Hope this answer helps more people if they get the same problem.
Please check your method result type of controller
Change this:
#Contoller()
export class MyController {
// ...
async myMethod() {
return {}
}
}
to:
#Contoller()
export class MyController {
// ...
async myMethod():Promise<any> {
return {}
}
}
I created a react-app which I deployed online with npm run build, now everything locally works fine but when I try to load a page on my app it gives a error in Container.js ( no idea what this file is and what it does )
i've tried to reinstall all the node_modules without any result so I cloned my repo fresh but still without any result
Container.js:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _reactRedux = require('react-redux');
var _Container = require('../components/Container');
var _Container2 = _interopRequireDefault(_Container);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
/**
* src/containers/Container.jsx
*/
var mapStateToProps = function mapStateToProps(store, ownProps) {
return {
items: store[ownProps.reduxStoreName].content[ownProps.reduxUid].filter(function (item) {
return item.parentId === ownProps.itemId;
})
};
};
exports.default = (0, _reactRedux.connect)(mapStateToProps)(_Container2.default);
Error in console: Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined
well, like #Pointy mentioned in his comment, it basically means that store[ownProps.reduxStoreName].content[ownProps.reduxUid] is undefined.
It is not the file which is causing the error, its the specific line. When the code reaches this line and tries to execute it- that store[ownProps.reduxStoreName].content[ownProps.reduxUid] parameter is undefined so it crushes.
We cannot tell you where the error is, we'd need the code of your whole app to follow the execution flow.
You have to follow it yourself, and understand why there is not an array in that variable when the code gets there.
As a general idea, try figure out the following:
when and where that variable is initialized?
when and where do you call mapStateToProps?
are you absolutely sure that the code which answers question 1 is executed before the code which answers to question 2? (maybe there is an asynchronous execution problem you didn't think about which causes your code to execute at the wrong order)
if it does- maybe the way you initialize those variables at the beggining is not correct? maybe you use a 3rd party library / function to initialize them, but not actually getting the result you expecting? or maybe you're using it wrong, or parsing the result wrong?
I have the following Lodash function
flow(find({ id: args.roleRateId }), get('chargeRate'))(
args.roleRates
)
however, it doesn't work for what i need, inside the get i need to add get('chargeRate', args.roleRate) so it can get the chargeRate form the args.roleRate, but when i add this I do get
Uncaught TypeError: Expected a function
Anyone has any ideea why is that and how to fix it?
First you import import get from 'lodash/get'.
Then args.roleRate.chargeState would be got like get(args.roleRate, 'chargeState') or get(args, 'roleRate.chargeState').
So I looked around, looking for solutions for this problem else where and including here, but I keep getting the error
"Cannot read property 'testModule' of undefined."
main.js:
var testing = require('./lib/test.js');
console.log(testing.testModule('user'));
./lib/test.js
module.exports = {
testModule: function(test){
return 'Hello '+test+' from module!';
}
};
What am I doing wrong and what can I do to fix this issue?
Fixed the error.
In my original code (not here) I assigned the variable testing as test and called a variable that was non-existent.
Thanks for the tips on the directory structures, though. I appreciate it.
I suck :(
I am using requireJS for the first time. I got it working fine then came to optimize the files to minify and concatenate and now I get the error "Uncaught TypeError: undefined is not a function" the error is on line 8175 of front-built.js. I have left the file unminifed for this question to make it easier to identify the problem.
My main JS file before optimization looks like this (works fine):
http://thebeer.co/js/front.js
And after optimization (throws the error on line 8175):
http://thebeer.co/js/front-built.js
Hope someone is more familier with requireJS than me and can fix this issue. Is may be the way I'm including my JS file before optimization. I'm really not sure.
I see the problem there:
define('globals',["jquery"],(function($){
var siteWrap = $('#siteWrap'),
membersTab = $('#membersTab'),
mID = siteWrap.attr('mID');
if(window.location.host == "dev.thebeer.co"){
var staticURL = "http://static.thebeer.co";
}else{
var staticURL = "https://static.meshmesh.us";
}
// ... SNIP SNIP ....
})());
You're not passing jQuery to the anonymous function, therefore $ is undefined inside the function. That last line should be like this:
})(jQuery));