-
Notifications
You must be signed in to change notification settings - Fork 179
Expo/RN: Cannot read property `defineProperty' of undefined #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@svile Hi,
Interesting. TypeBox doesn't call TypeBox already follows the Babel recommendation by defining Object with What would be helpful though is seeing a full stack trace + the line of code that faults. Keep in mind, I am not a Android or IOS developer, and I can't trivially reproduce this side without installing the tooling. It might be good to direct this issue to the Expo project. Also, if you can debug via making edits to TypeBox in node_modules, that might lend a bit of insight into the problem. Related PR: #1055 Let me know if you can provide a stack trace. |
@sinclairzx81 hi and thank you for the quick response and useful information! Here's the full stack trace for React Native Web, which is also experiencing the same issues as the native device bundles:
I was also able to narrow it down to the // ...
import { Static } from "@sinclair/typebox";
const { Type } = require('@sinclair/typebox');
// ...
export const TestSchema = Type.Object({
test: Type.String({
description: "Test string.",
}),
});
// ... |
@svile Hiya, thanks for the follow up!
at require (/Users/svile/my-app/node_modules/metro-runtime/src/polyfills/require.js:92:7)
at factory (/Users/svile/my-app/node_modules/@sinclair/typebox/build/esm/type/object/index.mjs:1:1) Yeah, looking at these two lines, it certainly does look like a shadowing conflict related to how metro (or more likely babel) is polyfill-ing for ESM and and running into shadowing issues for import { CreateType } from '../create/type.mjs';
import { Kind } from '../symbols/index.mjs';
// ------------------------------------------------------------------
// TypeGuard
// ------------------------------------------------------------------
import { IsOptional } from '../guard/kind.mjs';
function RequiredKeys(properties) {
const keys = [];
for (let key in properties) {
if (!IsOptional(properties[key]))
keys.push(key);
}
return keys;
}
/** `[Json]` Creates an Object type */
function _Object(properties, options) {
const required = RequiredKeys(properties);
const schematic = required.length > 0 ? { [Kind]: 'Object', type: 'object', properties, required } : { [Kind]: 'Object', type: 'object', properties };
return CreateType(schematic, options);
}
/** `[Json]` Creates an Object type */
export var Object = _Object; There really isn't much else TypeBox can do here (afaik), but if the CJS output is successful, that might be the way to go. In the past, users who have hit this problem usually end up visiting project after project up the dependency chain until they reach Babel, where the solution in Babel would be to fully qualify the call with From a library stand point though, TypeBox shouldn't really need to be bundler / transpiler aware, and the need for it to prefix with The only thing I can recommend is perhaps tinkering with Expo configurations, setting the ES target to 2020+ (maybe you can avoid all polyfills with a newer ES target), or submitting an issue to Expo -> Metro -> Babel. I vaguely recall Metro (or Expo) having a configuration workaround (I can't find the link but remember something), so it might be worth chasing up. Let me know how you go. I am genuinely open to updates in TypeBox just so long as they don't result in API interface changes. If you do find anything, or can advise insights on things happening downstream in these tooling projects, let me know. Cheers! |
@sinclairzx81 thank you very much! I'll try your suggestions and will close this as I do agree with you + there is also currently a workaround. I'll likely re-open or comment if I find anything else useful to contribute. |
Hi @sinclairzx81! We just received an issue report related to this error: expo/expo#37171. I think this is just a quirk in Metro and how it transpiles the ESM modules. You can see a full explanation here - but the TL;DR; is:
One thing that could help for Metro specific, which technically is also valid ESM is using something like this instead: /** `[Json]` Creates an Object type */
-export var Object = _Object
+export { _Object as Object }; Important If you have multiple exports, this does overwrite all previous export statements. But because src/type/object/object.ts only has 1 single non-type export, this should be fine for this file. This would avoid changing the Hope this helps! |
Uh oh!
There was an error while loading. Please reload this page.
I just ran into this issue on a new default Expo project created using the latest
[email protected]
Steps to reproduce:
npx create-expo-app@latest
app/(tabs)/index.tsx
:Uncaught error: Cannot read property 'defineProperty' of undefined
The text was updated successfully, but these errors were encountered: