Build fails with ReferenceError: window is not defined - gridsome

When I run gridsome build I get
ReferenceError: window is not defined
at Object. (src/gapi_client.js:1:9)
at webpack_require (webpack/bootstrap:25:0)
at Module. (assets/js/app.f322a6ac.js:68956:19)
at webpack_require (webpack/bootstrap:25:0)
at Object. (assets/js/app.f322a6ac.js:56344:18)
at webpack_require (webpack/bootstrap:25:0)
at assets/js/app.f322a6ac.js:118:18
at Object. (assets/js/app.f322a6ac.js:121:10)
at o (/home/s/somegrid/node_modules/vue-server-renderer/build.prod.js:1:77607)
at /home/s/somegrid/node_modules/vue-server-renderer/build.prod.js:1:78200
my main.js has import './gapi_client' at the very top.
My env:
System:
OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
CPU: (2) x64 AMD A6-4400M APU with Radeon(tm) HD Graphics
Binaries:
Node: 11.6.0 - /usr/local/bin/node
Yarn: 1.15.2 - ~/.yarn/bin/yarn
npm: 6.13.6 - /usr/local/bin/npm
Browsers:
Chrome: 81.0.4044.113
Firefox: 75.0
npmPackages:
gridsome: ^0.7.14 => 0.7.14
npmGlobalPackages:
#gridsome/cli: 0.3.1
Some questions:
Why is gapi_client.js referencing window?
Should gapi_client.js be imported only when process.isClient is true?
I changed the code in main.js as follows:
if (process.isClient) {
window.gapi_client = require('./gapi_client')
}
Now my build seems to go thru that step but fails with
Error: No native build was found for runtime=node abi=67 platform=linuxglibc arch=x64
at Function.module.exports.load.path (node_modules/node-gyp-build/index.js:56:0)
at load (node_modules/node-gyp-build/index.js:18:0)
at Object. (node_modules/leveldown/binding.js:1:41)
at Object. (assets/js/app.ce34d4e7.js:28227:30)
at webpack_require (webpack/bootstrap:25:0)
at Object. (node_modules/leveldown/leveldown.js:3:16)
at webpack_require (webpack/bootstrap:25:0)
at Object. (node_modules/level/level.js:1:43)
at webpack_require (webpack/bootstrap:25:0)
at Object. (assets/js/app.ce34d4e7.js:9411:13)

Try process.browser instead of process.isClient

I changed the code to:
if (process.isClient) {
window.gapi_client = require('./gapi_client').default
}
And it works!

Related

Sentry on React Native: Building for iOS breaks with "property 'options' not found on object of type 'PrivateSentrySDKOnly'"

I am using CircleCI to build for iOS (and Android) and recently, the iOS build fails with these error messages:
Compiling RNSentry.m
❌ /Users/distiller/project/node_modules/#sentry/react-native/ios/RNSentry.m:107:79: property 'options' not found on object of type 'PrivateSentrySDKOnly'
if (appIsActive && !sentHybridSdkDidBecomeActive && (PrivateSentrySDKOnly.options.enableAutoSessionTracking || PrivateSentrySDKOnly.options.enableOutOfMemoryTracking)) {
^
❌ /Users/distiller/project/node_modules/#sentry/react-native/ios/RNSentry.m:107:137: property 'options' not found on object of type 'PrivateSentrySDKOnly'
if (appIsActive && !sentHybridSdkDidBecomeActive && (PrivateSentrySDKOnly.options.enableAutoSessionTracking || PrivateSentrySDKOnly.options.enableOutOfMemoryTracking)) {
^
❌ /Users/distiller/project/node_modules/#sentry/react-native/ios/RNSentry.m:155:39: property 'getSdkName' not found on object of type 'PrivateSentrySDKOnly'
#"name": PrivateSentrySDKOnly.getSdkName,
^
❌ /Users/distiller/project/node_modules/#sentry/react-native/ios/RNSentry.m:195:34: property 'options' not found on object of type 'PrivateSentrySDKOnly'
if (PrivateSentrySDKOnly.options.debug
It has once worked to build for iOS, and I think this has something to do with the version of Sentry; I think I tried to update the Sentry version to 4.9.0, only to find that 4.9.0 has some serious issues (I think). I am not smart enough to dechiffer exactly what the conclusions here are, but I think it relates:
https://github.com/getsentry/sentry-cocoa/issues/1665
https://github.com/getsentry/sentry-react-native/issues/2530
(I was looking for another URL that related, but cant find now)
Android works to build with the configs and whatnot, but iOS fails. I am not sure what do to do resolve this, and I would like some input =)
the package.json has Sentry 4.8.0:
"dependencies": {
"#react-native-async-storage/async-storage": "^1.17.4",
"#react-native-community/cli-platform-android": "^6.3.0",
"#sentry/react-native": "4.8.0",
"#turf/distance": "^6.0.1",
"axios": "^1.1.1",
"dotenv": "^16.0.0",
"eventing-bus": "^2.0.1",
"jetifier": "^2.0.0",
"lodash": "^4.17.15",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
"patch-package": "^6.4.7",
"react": "17.0.2",
"react-native": "0.67.4",
Here is the rest of my config/setup:
PS C:\Github\alfaonlinev3> npx react-native doctor
Common
✓ Node.js
✓ yarn
Android
✓ JDK
✖ Android Studio - Required for building and installing your app on Android
✓ Android SDK - Required for building and installing your app on Android
✓ ANDROID_HOME
Errors: 1
Warnings: 0
Note: I have Android Studio installed, and it is working for Android native project. No idea why doctor complains or how to resolve it, other than downloading another copy of Android studio?
envinfo:
Visual Studio code: 1.73.1
System:
OS: Windows 10 10.0.19044
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 5.01 GB / 31.95 GB
Binaries:
Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
Managers:
pip2: 19.2.3 - C:\Python27\Scripts\pip2.EXE
pip3: 21.1.1 - C:\Python39\Scripts\pip3.EXE
Utilities:
Git: 2.34.1.
SDKs:
Android SDK:
API Levels: 28, 29, 30, 31, 33
Build Tools: 28.0.3, 29.0.0, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
IDEs:
VSCode: 1.73.1 - C:\Program Files\Microsoft VS Code\bin\code.CMD
Visual Studio: 17.3.32519.111 (Visual Studio Community 2022), 16.11.32106.194 (Visual Studio Community 2019)
Languages:
Java: 19.0.1
Python: 3.9.5
Databases:
SQLite: 3.32.2 - C:\Users\wagge\AppData\Local\Android\Sdk\platform-tools\sqlite3.EXE
Browsers:
Chrome: 107.0.5304.121
Edge: Spartan (44.19041.1266.0), Chromium (107.0.1418.56)
Internet Explorer: 11.0.19041.1566
IDEs:
Android Studio: Not Found
Visual Studio: 17.3.32519.111 (Visual Studio Community 2022), 16.11.32106.194 (Visual Studio Community 2019)
Languages:
Java: 19.0.1
npmPackages:
#react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.4 => 0.67.4
react-native-windows: Not Found
npmGlobalPackages:
*react-native*: Not Found
UPDATE
I ran npm-update, it suggested updating sentry to 4.10.1. After that was done, I see this change in package.json:
also yarn.lock
but still, the builds fails with the same error.
UPDATE 2
I check podfile.* and I see stuff like:
podfile.lock:
- RNSentry (3.4.2):
- React-Core
- Sentry (= 7.11.0)
- RNSnackbar (2.4.0):
- React-Core
- RNSVG (9.13.6):
- React
- Sentry (7.11.0):
- Sentry/Core (= 7.11.0)
- Sentry/Core (7.11.0)
The file podfile does not contain "sentry" at all.
Looks like it is your problem:
https://github.com/getsentry/sentry-react-native/pull/2599/files
Try to upgrade react native sentry to 4.10.1
From your podfile.lock it looks like you have an old version of the RNSentry pod installed.
- RNSentry (3.4.2):
Try to run the following:
cd ios
pod update RNSentry
The RNSentry must be the same version as #sentry/react-native. So in your case it should've been 4.10.1.

React-native monorepo iOS release build crash

I have a monorepo with this architecture :
├── node_modules
├── packages
├── app # React native project
├── android
└── ios
├── common # TS package
└── web # Next JS project
In common package I have some shared services such as API calls for web front and mobile app.
During development phases, build and run process were working fine for both app and web.
Now I would like to publish my app to the app store but I'm not able to compile a working release ios app.
I have this crash logs when launching the app :
022-06-02 15:33:14.173898+0200 XXXX[33899:2579321] *** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.', reason: 'Unhandled JS Exception: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the applica..., stack:
<unknown>#13:289
value#760:3143
<unknown>#760:747
value#760:2538
value#760:719
value#(null):(null)
'
*** First throw call stack:
(0x185361288 0x19e05b744 0x1003c0538 0x10043fd8c 0x10044066c 0x1852e9b24 0x185307610 0x18533e5fc 0x1003d7bd4 0x1003f5e98 0x1003f5ac8 0x184fc6e6c 0x184fc8a30 0x184fd0124 0x184fd0c80 0x184fdb500 0x1f6c240bc 0x1f6c23e5c)
libc++abi: terminating with uncaught exception of type NSException
I follow this article to build monorepo : https://medium.com/#ratebseirawan/react-native-0-63-monorepo-walkthrough-36ea27d95e26.
I have in my xcode project, Build Phases > Bundle React Native code and images :
set -e
export NODE_BINARY=node
export EXTRA_PACKAGER_ARGS="--entry-file packages/app/index.js --reset-cache"
../../../node_modules/react-native/scripts/react-native-xcode.sh "packages/app/index.js"
and in Start packager :
export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../../../node_modules/react-native/scripts/.packager.env"
if [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then
if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then
if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then
echo "Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"
exit 2
fi
else
open "$SRCROOT/../../../node_modules/react-native/scripts/launchPackager.command" || echo "Can't start packager automatically"
fi
fi
In my AppDelegate.m
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:#"packages/app/index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:#"main" withExtension:#"jsbundle"];
#endif
}
metro.config.js :
const {getDefaultConfig} = require("metro-config");
const path = require('path');
module.exports = (async () => {
const {
resolver: {sourceExts, assetExts}
} = await getDefaultConfig();
return {
projectRoot: path.resolve(__dirname, '../../'),
transformer: {
babelTransformerPath: require.resolve("react-native-svg-transformer"),
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
assetExts: assetExts.filter(ext => ext !== "svg"),
sourceExts: [...sourceExts, "svg"]
}
};
})();
Env :
react-native 0.67.4
output of npx react-native info :
System:
OS: macOS 12.3.1
CPU: (8) arm64 Apple M1
Memory: 555.95 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.5.0 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8092744
Xcode: 13.4/13F17a - /usr/bin/xcodebuild
Languages:
Java: 17.0.2 - /usr/bin/javac
npmPackages:
#react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
I think that the main.js bundle generated is at the wrong place but I don't find the solution, have you any idea ?
Thanks !
in your packages/app/metro.config.js file did you do the changes that are shown in the article?
also and could you share that file.
(The article that you mentioned was specifically supposed to work with ReactNative 0.63, at that time there was little to no tooling to work with React Native on a Monorepo but now we have great tooling and support for it that will solve these annoying issues out of the box, I personally have been using https://nx.dev/guides/react-native)
for your issue tho I can try to help but there might be many things that could cause the error, one might be behind the M1 chip (doesn't have to be tho)
another info that might help, I read the patch notes of RN version 0.65 or 0.66 that they fixed an issue with monorepos where metro doesn't work nicely with symlinks so that might help.
but if I where you, I would clone the NX monorepo template and see their setup and compare with what you have (Files I would look at are metro.config. info.plist. babel.config)
Atm, I found a temporarily workaround :
I added in packages/app/package.json :
"build-prod:ios": "react-native bundle --platform ios --dev false --entry-file ./packages/app/index.js --bundle-output ios/MyAppName/main.jsbundle --assets-dest ios",
in Xcode > Build Phases > Copy Bundle Ressources :
add main.jsbundle
Comment all lines in "Bundle React Native code and images" and "Start packager"
For each new release, I now need to run yarn build-prod:ios before use xcode to build.

Error: The non-abstract class 'ChromeProxyService' is missing implementations for these members:

I did a pub build this morning and all of a sudden, something that was compiling fine yesterday, with no changes today, is breaking.
Failed to precompile webdev:webdev:
../../../.pub-cache/hosted/pub.dartlang.org/dwds-3.1.3/lib/src/services/chrome_proxy_service.dart:40:7: Error: The non-abstract class 'ChromeProxyService' is missing implementations for these members:
- VmServiceInterface.getSupportedProtocols
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class ChromeProxyService implements VmServiceInterface {
^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dartlang.org/vm_service-4.1.0/lib/src/vm_service.dart:745:24: Context: 'VmServiceInterface.getSupportedProtocols' is defined here.
Future<ProtocolList> getSupportedProtocols();
^^^^^^^^^^^^^^^^^^^^^
Precompiling executables... (1.9s)
I've done a cache repair, another get to see if there are newer versions, I've done an upgrade just to be sure, but as soon as I hit activate webdev, I get the above error.
~/Code/dart-sdk-2.8.4/bin/pub cache repair
~/Code/dart-sdk-2.8.4/bin/pub get
~/Code/dart-sdk-2.8.4/bin/pub upgrade
~/Code/dart-sdk-2.8.4/bin/pub global activate webdev
~/Code/dart-sdk-2.8.4/bin/pub global run webdev build --verbose --output=web:build -- --delete-conflicting-outputs || exit
This is my pubspec.yaml, not much in there
name: blah
version: 0.0.0
description: Blah
environment:
sdk: ">=2.8.0 <3.0.0"
dev_dependencies:
build_runner: ^1.10.0
build_test: ^0.10.2
build_web_compilers: ^2.11.0
test: ^1.0.0
And I'm on Dart 2.8.4 (getting the same on other versions of Dart, so not sure if the Dart version has an effect)
Any ideas?
Seems like there's a temp workaround
pub global activate webdev 2.5.6
https://github.com/dart-lang/webdev/issues/1036
https://github.com/dart-lang/webdev/issues/1037

package "dart_to_js_script_rewriter" is not a dependency

I just started learning dart.
first I created an angular2-dart based project from https://angular.io/docs/dart/latest/quickstart.html and it worked properly.
now I want to add auth0-lock dart package from https://pub.dartlang.org/packages/auth0_lock, so I modified pubspec.yaml to the following:
name: go_dart_angular2_zingchart
description: Go Dart Angular2 with ZingChart Started Kit
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
dependencies:
angular2: ^2.0.0-beta.18
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
auth0_lock: ^0.1.0
transformers:
- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'
entry_points: client/web/main.dart
- dart_to_js_script_rewriter
and now when I execute pub get I get the following error:
Error on line 15, column 3 of ../../../.pub-cache/hosted/pub.dartlang.org/auth0_lock-0.1.0/pubspec.yaml: Error loading transformer "dart_to_js_script_rewriter": package "dart_to_js_script_rewriter" is not a dependency.
- dart_to_js_script_rewriter
^^^^^^^^^^^^^^^^^^^^^^^^^^
since I'm new to dart and not entirely sure what I'm doing.. I have no idea how to fix this :)
any ideas ?
thanks!
I get the same error when adding auth0_lock: ^0.1.0 to my dependencies and running pub get. The error message says that "dart_to_js_script_rewriter" is not a dependency in the pubspec.yaml of the auth0_lock package. It looks like it's added under dev_dependecies if you look here. Dev dependencies of any dependent packages are ignored. Pub only gets your package’s dev dependencies.
So I think this is a problem in their package.
So, what I did was I went to https://github.com/andresaraujo/auth0_lock.dart and cloned the package, added it into my own project root in a directory called auth0_lock. And then, in my pubspec.yaml i put:
auth0_lock:
path: auth0_lock
After that I can import it using
import 'package:auth0_lock/auth0_lock.dart';

Usage of $TRAVIS_OS_NAME in .travis.yml

I want to test a project on multiple platforms, so I am using according to the docs os: and $TRAVIS_OS_NAME. But I seem to be missing something. My .travis.yml looks as follow:
os:
- osx
before_install:
- ./.travis.$TRAVIS_OS_NAME.before_install.sh
install:
- ./.travis.$TRAVIS_OS_NAME.install.sh
script:
- ./.travis.$TRAVIS_OS_NAME.script.sh
But i get the following error:
$ ./.travis.$TRAVIS_OS_NAME.before_install.sh
/home/travis/build.sh: line 41: ./.travis.linux.before_install.sh: No such file or directory
So it seems that the os: directive is ignored.
Am I missing something?
I have not included os: -linux as the tests scripts are not ready yet.

Resources