Cannot read properties of undefined when trying to use a server function
axeligl opened this issue · 7 comments
Hi! I'm having this error and I don't know if I'm doing something wrong or what.
I declared a server function in sheets.js, exported it in index.ts, used it on a component on client side and having a 'Cannot read properties of undefined ' error.
I make a simple example and still doesn't work.
This is index.ts
import {
doGet
} from './ui';
import { getInfo } from './sheets';
// Public functions must be exported as named exports
export {
doGet,
getInfo,
};
This is sheets.js
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const getSheet = (name) => SpreadsheetApp.setActiveSheet(spreadsheet.getSheetByName(name));
export const getInfo = () => {
return "prueba"
}
And this is the component
import React, { useState, useEffect } from 'react';
import serverFunctions from '../../utils/serverFunctions';
export default function MesitasApp() {
serverFunctions.getInfo().then(console.log).catch(alert)
return (
<div className="App">
probando
</div>
);
}
When I deploy and run the app, there's an error on the console:
TypeError: Cannot read properties of undefined (reading 'getInfo')
I used the previous version of this repo without any problem.
Probably I'm doing something wrong but I'm stucked and wish to solve this problem soon.
Thanks.
You using any additional libraries? There was an issue with react router do in case you're trying that.
No. Its a plain clone of this repo
Does a brand new clone, with no modifications, work for you?
I tried the project without modifications and it works. Also I read that discussion but nothing works.
I have this warning when deploy:
export 'default' (imported as 'serverFunctions') was not found in '../../utils/serverFunctions' (possible exports: __esModule, serverFunctions)
Seems to be related to the problem.
Looks like you may be using default import instead of named import.
Try: import { serverFunctions } from '../../utils/serverFunctions';
Yes. I realized that on your code was different. Just tried that and it's solved. I came here to comment.
Thanks!