Module Federation in Nx and Angular generates an error loading styles.js - nrwl-nx

I am following the article describing setting up module federation: https://nx.dev/l/a/guides/setup-mfe-with-angular
Starting with generating the workspace, adding the angular plugin, and adding the dashboard application.
When serving the dashboard application I get an error from styles.js:
Uncaught SyntaxError: Cannot use 'import.meta' outside a module
It is being loaded as:
<script src="styles.js" defer></script>
Doing some quick searches seems to indicate that this thing should have type="module" on it.
However there doesn't seem to be any kind of configuration I can find to modify the line being added to the index.html.
I have checked the regular template generated by angular, it uses the defer style to everything, so the other js file entries are being changed to type="module" some place. The normal styles.js also does not contain any "import.meta" string.
Any solution would be helpful.

TL;DR: thats fine. You should not see this error in the production
There is a note on the https://nx.dev/guides/setup-mfe-with-angular you mentioned saying:
NOTE: When serving MFEs in dev mode locally, there'll be an error output to the console, import.meta cannot be used outside of a module, and the script that is coming from is styles.js. It's a known error output, but it doesn't actually cause any breakages from as far as our testing has shown. It's because the Angular compiler attaches the styles.js file to the index.html in a tag with defer.
It needs to be attached with type=module, but doing so breaks HMR. There is no way of hooking into that process for us to patch it ourselves.
The good news is that the error doesn't propagate to production, because styles are compiled to a CSS file, so there's no erroneous JS to log an error. It's worth reiterating that there's been no actual errors or breakages noted from our tests.

Check the scriptType
This issue has to do with how the imports are set up in the compiled app. You can update the scriptType in your webpack.config.js by adding the scriptType:
module.exports = {
output: {
uniqueName: "YourUniqueAppName",
publicPath: "auto",
scriptType: "text/javascript"
},

Related

Cypress Component testing fails with 404 on component fetch

Updates
Based on comments and further tests I now suspect that the problem has somewhat to do with access restriction on the path, not the path itself. It's however not clear to me what actually is the cause, as there is no clear hints of it.
I now use another project for my evaluation, without access control, and it works. So the problem seems to be related to access control.
I leave the question as is, for future reference.
I am following this Cypress Quickstart: Vue guide to try out the new component testing for Vue. I already have "e2e" Cypress test working, and it's seemingly some basePath or other configuration/path issues, specifically with component test, I am dealing with now.
Problem
The browser does not carry out the test, waiting forever, saying in the dev tools console:
http://localhost:8080/__cypress/iframes/C:/work/swisscom/prixx/WebGui/Web/cypress/components/PersonEdit.cy.js....404 Not Found
I get the following error in the VS Code terminal:
GET /__cypress/iframes/C:/work/swisscom/prixx/WebGui/Web/cypress/components/PersonEdit.cy.js 404 49.560 ms - 105
Setup
Here's my cypress.config.ts
import { defineConfig } from 'cypress';
export default defineConfig({
...
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config);
},
baseUrl: 'http://localhost:2623/'
},
component: {
devServer: {
framework: 'vue',
bundler: 'webpack'
}
}
});
It's Vue2, Webpack, Cypress v10.6.0, using Google Chrome.
I start the Cypress controlled Browser from the Cypress App (Google Chrome points at http://localhost:8080/__/#/specs)
When clicking the test, the address bar in the browser now shows "http://localhost:8080/__/#/specs/runner?file=cypress/components/PersonEdit.cy.js" which looks reasonable
What I have tried/found
The test file exists a the given absolute location. However, I consider the use of this absolute path a telltale sign of my problem.
I have a baseUrl configured for e2e, but I can not find a way to configure one for component testing
The config, when inspected with the controlled browser shows the following:
From http://localhost:8080/__/#/settings, "Resolved Configuration":
//...
arch: 'x64',
baseUrl: null,
//...
Somehow, the controlled browser translates the relative path to an absolute path. Why is that?
Question
How can I fix/configure the path for fetching my Cypress Component Test spec?

TYPO3 backend form module gives error when creating forms

I'm currently running TYPO3 version 8.7.18 and running a site_package that was made by using the site package builder: link
Whenever I try to add a form by using the default backend forms module I get the default message Oops, an error occurred! along with that the following error
TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\AddHmacDataConverter not found
Searching for the issue I get several hits on the Gitlab but these do not provide any solution.
Along with this setup, I've added the forms module as a static include in my top-level template.
do you have a composer installation or an extension manager build up?
If a class is not found you may need to rebuild the autoloader information.
My error turned out to be caused by a corrupt installation. I've had to upload the file AddHmacDataConverter.php in the following path /public_html/typo3/sysext/form/Classes/Domain/Configuration/FormDefinition/Converters. A very weird error indeed.
For those that came here with the same error, make sure to check that folder. Apart from that add the news as a static inclusion in your top domain. You could also follow #Bernd Wilke's idea which s to disable the extension, clear all system caches (and additionally remove typo3/temp/autoload and then active the extension again.

how to setup Karma with Ui5

I have a question related to karma and ui5.
Current situation is as follows:
I use karma-openui5 and load ui5 via bower. Karma-openui5 simply adds some bootstrap information and the core-file itself:
files.unshift({pattern: ui5path, included: true, watched: false, served: true});
which leads to this head entry:
<script type="text/javascript" src="/base/bower_components/openui5-sap.ui.core/resources/sap-ui-core.js" crossorigin="anonymous"></script>
Ui5 is designed to load everything else related to the core-file but is served by sap in different bower packages this means, request is:
http://localhost:9876/base/bower_components/openui5-sap.ui.core/resources/sap/m/library-preload.js
but it's actually located under
http://localhost:9876/base/bower_components/openui5-sap.m/resources/sap/m/library-preload.js
I could overcome this problem with proxy entries. But i can`t include the .css files which one are in a separate bower package. I can't see a way to proxy only */**/.css requests to another directory. Therefore this way just doesn't work well.
Openui5 has already some middleware (connect-openui5) to resolve this problems and server everything as expected under localhost:XXXX/resources/.
How and can i add custom script tags in karma? like:
<script type="text/javascript" src="resources/sap-ui-core.js"></script>
How can i add a middleware (connect-openui5) to handle all requests to /resources/**/*?
The solution was to use the connect middleware from sap, started with grunt and proxy to this.
I packed everything in a yeoman generator, if anyone is interested in the setup.
https://www.npmjs.com/package/generator-ui5

Structuring webpack config for use with karma testing

I would like to create a test suite which will be run with karma against my app which is using webpack to build itself. I have two entrypoints, app and vendors. These are set up through my webpack.config.js file here. The resulting bundle.js should contain both of these entrypoints in its generated file.
My karma (mocha) tests residing in test/spec/*_spec.js are currently pointing to specific components, via require statements like:
var app = require('../src/scripts/App')
They also utilize react/jsx which seems to be causing problems during the test run where I get jsx errors:
Module parse failed: /Users/dmarr/src/status/test/spec/app_spec.js Line 10: Unexpected token <
You may need an appropriate loader to handle this file type.
I'd like to keep test runs quick as possible as well as fast build times for testing with webpack-dev-server during development by minimizing babel transforms to only where needed.
What do I need to do in karma.conf.js to get my builds working? Here is the karma.conf.js file I'm playing around with.
Note, that I do have this working without breaking out the vendor bundle here: https://github.com/bitwise/status
Thanks for any help,
Dave
In a similar setup, disabling CommonsChunkPlugin (for testing only) worked for me. Give it a shot!

Using coffeescript with basic Yeoman project.

I've used Yeoman to make a quick project skeleton using the yo webapp generator command. In the resulting Gruntfile I see that it's setup to compile CoffeeScript but it seems like its just sticking compiled files in a tmp folder.
coffee: {
dist: {
files: {
'.tmp/scripts/coffee.js': '<%= yeoman.app %>/scripts/*.coffee'
}
},
},
How do these get included in the project during development. I'm not using RequireJS.
The yeoman docs are unclear on how to use coffeescript. They only mention that it gets automatically compiled.
Using yeomen 1.0.0-rc1.4. I use:
$ yo angular --coffee
The resulting project has controller and app scripts in CoffeeScript.
grunt configuration file remains in js (what is not really a problem).
Running
$ grunt test
runs tests and all seems fine.
$ grunt server
is also doing what one expects (build the app, test it, starts server, opens the app in web browser and starts watching for changes, so if I change a coffee script file, it is quickly reflected in the web broser.
Documentation also states, one can use yo to add particular pieces like
angular:controller
angular:directive
angular:filter
angular:route
angular:service
angular:decorator
angular:view
each can be called with a --coffee switch and get the script in CoffeeScript, e.g.:
yo angular:controller user --coffee
I just found an issue in the github repo referencing this problem. https://github.com/yeoman/generator-webapp/issues/12
It offers a temporary solution: https://github.com/yeoman/generator-webapp/issues/12#issuecomment-13731929