Internal server error: Cannot read property 'useQwikCityEnv' of null - qwik

I'd followed the integration instructions to connect my builder.io account to my qwik application running on localhost:5143 and setup a test page to start playing with visual editor but I got this error on localhost:
10:47:31 PM [vite] Internal server error: Cannot read property 'useQwikCityEnv' of null
File: /Users/mra/development/personal/qwik/node_modules/#builder.io/qwik-city/index.qwik.mjs:265:14
263| };
264| const QwikCityProvider = /* #__PURE__ */ componentQrl(inlinedQrl(() => {
265| const env = useQwikCityEnv();
| ^
266| if (!env?.params)
267| throw new Error(`Missing Qwik City Env Data`);
and I didn't find any resources online why it happened.

After several tries I'd found the issue and the solution:
instead of running the local app with dev command which is a browser only render, you should run start command to enable local ssr as well;
npm run start

Related

Migrating from local GitLab to cloud based GitLab results in npm test failing: "TypeError: Cannot read property 'close' of undefined"

On our local build instance with GitLab running jest everything works fine. We are migrating everything to gitlab's cloud and running ci/cd there. The linter, build, etc. all work, but when it gets to npm test and tries to execute the tests, every one of them fails with the same error in same place:
FAIL tests/Charts.test.js
● Test suite failed to run
TypeError: Cannot read property 'close' of undefined
42 |
43 | afterAll(() => {
> 44 | browser.close();
| ^
45 | });
Feels like a dependency issue or configuration. Any help would be appreciated. LMK if something else is needed like package file.
We figured out the problem, turns out the xserver stuff wasn't installed and since we had headless set to false, the browser window couldn't open up.
Setting 'headless' to 'true' let us progress

Spartacus API calls return 504 (Gateway Timeout) when running using Server Side Rendering (SSR)

I'm trying to get Spartacus to work with SSR. When opening the default URL, http://localhost:4200, the storefront renders, as expected, but only after I clear the site data first. When I attempt to browse the storefront, API calls fail with a 504 (Gateway timeout). Chrome dev tools indicates the error is happening in the service worker. At this point, I'm wondering if I configured Spartacus incorrectly. When running Spartacus using yarn start rather than yarn serve:ssr, I can load the home page and browse the site normally.
OS: Ubuntu 16.04.6 LTS
Chrome Version: 73.0.3683.75
Node version: 11.15.0
Angular CLI version: 8.3.8
Yarn version: 1.19.1
ng new ssr-spartacus-app --style=scss
cd ssr-spartacus-app
ng add #spartacus/schematics --baseUrl https://localhost:9002 --baseSite cmssiteuid --pwa --ssr
rm src/app/app.component.html
echo "<cx-storefront>Loading...</cx-storefront>" > src/app/app.component.html
yarn build:ssr
yarn serve:ssr
Before running yarn build:ssr, I made following change to the app.module.ts file:
Before
context: {
baseSite: ['cmssiteuid'],
},
After
authentication: {
client_id: 'mobile_android',
client_secret: 'secret',
},
context: {
urlParameters: ['baseSite', 'language', 'currency'],
baseSite: ['cmssiteuid'],
},
I also set anonymousConsents to false. With this set to true, I was getting a lot of CORs errors.
If been scratching my head with this for a little while now and I'm hoping someone with more knowledge of Spartacus' inner workings can shed some light on why Spartacus is behaving this way with SSR.
I'm not sure that I can give you some certain recipe to fix the issue, obviously I need more details and logs relates to your problem, but still, based on my experience I can share with you some tips and tricks about how we should play with such issues (which relates to SSR).
Some set of theory which relates to SSR
https://angular.io/guide/universal (you can feel free to use Angular official documentation as a primary source, cuz Spartacus uses Angular OOTB features to make it works)
https://sap.github.io/spartacus-docs/server-side-rendering-in-spartacus/
https://enable.cx.sap.com/tag/tagid/spartacus (SSR related videos)
Practical approaches for debugging SSR
You should observe and analyze console output during starting your application in Node.js
You can use SSR configuration from example Storefront application (https://github.com/SAP/spartacus/tree/develop/projects/storefrontapp) like a starting point, cuz OOTB SSR works like a charm
Something from Spartacus team https://sap.github.io/spartacus-docs/how-to-debug-server-side-rendered-storefront/
Common set of theory to ensure that application has been configured correctly
SAP Commerce Cloud configuration for working with Spartacus https://sap.github.io/spartacus-docs/installing-sap-commerce-cloud/
Take a look on the guide https://sap.github.io/spartacus-docs/building-the-spartacus-storefront-from-libraries/ to ensure, that your frontend application has correct configuration
Double check your configuration which B2cStorefrontModule is using (here you can find an example project here https://github.com/SAP/spartacus/tree/develop/projects/storefrontapp)
Take a look on Network and Console browser tabs and try to resolve all errors
did you turn off PWA?
Turn PWA off.
As soon as Spartacus is installed in PWA mode, a service worker is installed, and it serves a cached version of index.html, along with the js files. This results in SSR being completely skipped. The following steps describe how to turn off PWA:
Check that there are no service workers registered in your app. If you do find any service workers, remove them.
Turn PWA off in your app module configuration, as follows:
StorefrontModule.withConfig({
backend: {
occ: {
baseUrl: 'https://[your_enpdoint],
},
},
pwa: {
enabled: false,
},
};
Rebuild your local Spartacus libraries by running the following command:
yarn build:core:lib
Build your local Spartacus shell app by running the following command:
yarn build --prod
Build the SSR version of your shell app by running the following command:
yarn build:ssr
Start Spartacus with the SSR server by running the following command:
yarn serve:ssr
If you are getting 504 after hitting the API service you need to check your API logs.
IF you have err log:
{"instant":{"epochSecond":1644915623,"nanoOfSecond":929833000},"thread":"hybrisHTTP1","level":"ERROR","loggerName":"org.springframework.web.servlet.DispatcherServlet","message":"Context initialization failed","thrown":{"commonElementCount":0,"localizedMessage":"Error creating bean with name 'cartEntriesController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultStockValidator' defined in ServletContext resource [/WEB-INF/config/v2/validators-v2-spring.xml]: Unsatisfied dependency expressed through constructor parameter 0: Could not convert argument value of type [de.hybris.platform.ycommercewebservices.stock.impl.DefaultCommerceStockFacade] to required type [de.hybris.platform.commercewebservices.core.stock.CommerceStockFacade]: Failed to convert value of type 'de.hybris.platform.ycommercewebservices.stock.impl.DefaultCommerceStockFacade' to required type 'de.hybris.platform.commercewebservices.core.stock.CommerceStockFacade'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'de.hybris.platform.ycommercewebservices.stock.impl.DefaultCommerceStockFacade' to required type 'de.hybris.platform.commercewebservices.core.stock.CommerceStockFacade': no matching editors or conversion strategy found","message":"Error creating bean with name 'cartEntriesController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultStockValidator'
You can try resolution:
Remove template extension ycommercewebservices extension from manifest.json, rebuild and redeploy with "Migrate Data" mode.

Angular CLI production build doesn't load on Apache

I build my production build with ng build --env=prod. When I try to serve it with Apache 2 all I see is Loading.... No error messages in the console, nothing.
The weird thing is that:
1) The development build works just fine
2) Also the production build works fine with the dev server and also with e.g. a Python ad-hoc server.
What could possibly cause this?
I only set in my environment.prod.ts:
export const environment = {
production: true
};

Titanium ACS issue

trying to create an ACS server using Titanium Studio. Following the example of pixgrid (https://github.com/appcelerator/pixgrid/), but always get an error when trying to run locally; console output:
[INFO] Installing dependencies...
[INFO] Dependencies installed.
[INFO] socket.io started
[ERROR] Error occurred. TypeError: Cannot call method 'init' of undefined
at Object.start (/app.js:8:7)
app.js listing:
var ACS = require('acs').ACS,
logger = require('acs').logger,
express = require('express'),
partials = require('express-partials');
// initialize app (setup ACS library and logger)
function start(app) {
ACS.init('***', '***');
logger.setLevel('DEBUG');
//use connect.session
app.use(express.cookieParser());
app.use(express.session({ key: 'node.acs', secret: "secret" }));
//set favicon
app.use(express.favicon(__dirname + '/public/images/favicon.ico'));
//set to use express-partial for view
app.use(partials());
//Request body parsing middleware supporting JSON, urlencoded, and multipart
app.use(express.bodyParser());
}
// release resources
function stop() {
}
Ofcourse I have my OATH key and secret at the ***. Same when running from command line (acs run).
I am running Titanium Studio, build 3.4.1.201410281727.
I can however publish the service, and then run it from the cloud without any issues. For development this is not ideal, so want to run it locally (local node.ACS server).
I guess there must be something wrong with where things are installed (only used default), or permissions. Anyone that got a clue how to fix this? Have spent some hours now searching the internet, but seem to be the only one with this exact problem. No clue what else to try.
Thanks for reading this far. If you require more information to help me, let me know.
Ok, I found the problem. They changed the way to use ACS in the last upgrade.
Classic mode was:
var ACS = require('acs').ACS;
ACS.init('<ACS Key>', '<ACS secret');
Now they changed it and ACS is a "module", like any other one, so you must use the new way. In the package.json file add it as a dependecy:
"dependencies": {
"acs-node": ">=0.9.2"
}
Install it: npm install acs-node
Now you can use it in its new format, on the app.js file:
var ACS = require('acs-node');
ACS.init('<App Key>');
It's all explained here: http://docs.appcelerator.com/cloud/latest/#!/guide/node_acs

Sencha build production error

I had successfully create production build. When i am trying to access production build from chrome than i am getting below error
Error: [Ext.Loader] Failed loading synchronously via XHR:
'src/field/Select.js'; please verify that the file exists. XHR status
code: 404
I had already included Ext.field.Select as requires in app.js.
Please tell me what should i do now
Before the start of your script, i.e., in app.js. Try adding Ext.Loader.setConfig({ enabled: true }); Check this
or
Also, Set the src of sdk in app.js prod environment dir: Ext.Loader