JSX not being recognized by Meteor - meteor

I am getting started with meteor and react. This is what I have done:
meteor create simple-react
meteor add kadira:flow-router
meteor add kadira:react-layout
mkdir client server lib
mkdir client/components
touch client/head.html
touch lib/routes.jsx
In routes.jsx, I have added the home page route:
FlowRouter.route("/", {
name: "Home",
action(params) {
ReactLayout.render(Home);
}
});
In home.jsx, I have created a simple Home component.
In the browser console, I am getting an error: Unable to find "/".
If I convert the routes.jsx to route.js, then the routes work. But, I am getting the error: Not able to find the Home component in the browser log.
For some reason, the JSX is not being recognized by Meteor and not getting compiled to JS.
I have all the required packages - ecmascript, jsx, react, react-runtime.

Though I added kadira:react-layout, I had to explictly add react to the packages list. Adding react to the packages list fixed it.

Related

Adding dependencies to the "ui" package of a Turborepo with Next.js throws Unexpected token 'export'

If you run
npx degit vercel/turbo/examples/with-react-native-web with-react-native-web
cd with-react-native-web
yarn install
To create a basic Turborepo that has a Nextjs application, a react-native mobile app with Expo and a ui package to share components between apps (there is a Button as an example already shared between the two apps), it works. But my ui package needs other dependencies, for example:
#fortawesome/fontawesome-svg-core,
#fortawesome/free-solid-svg-icons,
#fortawesome/react-native-fontawesome,
This is because the buttons that I want to render icons on my buttons. Once I install this dependency and try to use the button that has an icon, the Next.js app throws:
Unexpected token 'export'.
I understand this is because #fortawesome/react-native-fontawesome is using import/export syntax and needs to be transpiled to be used on the Next.js app, and I cannot make it work. I am trying to do this by adding this to my next.config.js:
transpilePackages: ['ui'],
I also tried using next-transpile-modules which i don't think is the right solution since next now supports what that package used to be for through transpilePackages
I also tried to specify that the ui package was "type": "module" but still, I am getting the same error.
How can you specify that those dependencies that belong to the ui package must be transpiled to be run by the browser?
I have checked the package #fortawesome/react-native-fontawesome
package.json of #fortawesome/react-native-fontawesome does not contain field "type": "module" but index.js contains:
export { default as FontAwesomeIcon } from './dist/components/FontAwesomeIcon'
therefore Next handles #fortawesome/react-native-fontawesome as non-ES module but this module contains export statement.
You mentioned transpilePackages field in next.config.js, so I think it may help with this issue (but pls check version of Next where transpilePackages appeared).

Nuxt using incorrect loader for scss

I am attempting to set up a nuxt project with scss. I added the following packages to my project:
"sass": "^1.37.0",
"sass-loader": "10",
and I updated nuxt.config.js to say the following to point to my new scss main file:
// Global CSS: https://go.nuxtjs.dev/config-css
css: [
'~/assets/sass/main.scss'
],
I had to use older versions because i was getting errors with certain functions I was using but i managed to get it working correctly on my local machine, and it builds just fine repeatedly as I update code as well.
I am now trying to deploy to staging on a Linux/nginx server and I am getting the following errors when building npm run build:
ERROR in ./assets/sass/main.scss (./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-1-1!./node_modules/postcss-loader/dist/cjs.js??ref--7-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--7-oneOf-1-3!./assets/sass/main.scss)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(1:1) postcss-custom-properties: <css input> Unknown word
> 1 | var(--font-size-2)/var(--font-ratio)
| ^
It looks like it's using css builder instead of sass builder! Does anyone know how to fix this? I doublechecked that the files on the server include the sass-loader and that the config is pointing to my .scss file, and i checked the documentation which states that Nuxt will automatically choose the correct loader.
What am I doing wrong?

MeteorJS not displaying anything on running application in localhost:3000

I am new to MeteorJS, and I am using Linux. As a basic newbie, I decided to stick to the tutorials on their official website. I went to follow the to-do list tutorial and selected the blaze option. At around step 6 or 7 the tutorial mentioned that you should start to see your application come together in your localhost:3000 when running it. After starting meteor and waiting for it to build the application I opened up localhost:3000. it looked like this:
AppImage. I thought there was an issue with my meteor installation so I ran
meteor npm install
to check if my installation was up to date and the output was:
up to date in 12.362s
I couldn't figure out what was wrong since the terminal wasn't sending any requests either so I opened the console in my browser and was greeted by the following errors:
Uncaught Error: Cannot find module './main.html'
at makeMissingError (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:232)
at Module.resolve (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:238)
at Module.moduleLink [as link] (modules.js?hash=20efd7567f62601be7ae21d11e21baf9bd63c715:307)
at module (main.js:1)
at fileEvaluate (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:346)
at Module.require (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:248)
at require (modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:268)
at app.js?hash=b426fd76718daefbb34707a544746de2f90dc26c:258
Is there any way to fix this?
Thanks a lot.
edit
Some of you wanted to take a look at the main HTML and js files in the client directory, so I've included them here:
main HTML and JS:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
import '../imports/ui/body.js';
Template.hello.onCreated(function helloOnCreated() {
// counter starts at 0
this.counter = new ReactiveVar(0);
});
Template.hello.helpers({
counter() {
return Template.instance().counter.get();
},
});
Template.hello.events({
'click button'(event, instance) {
// increment the counter when button is clicked
instance.counter.set(instance.counter.get() + 1);
},
});
<head>
<title>simple-todos</title>
</head>
How to read the stack trace:
at module (main.js:1)
In main.js on line 1 you are trying to import your main.html file.
Cannot find module './main.html'
Your main.js file likely has a statement like import './main.html'; on the first line.
This means that you must not have a main.html file adjacent to your JS file and so it cannot include it in the build.
Verify spelling, case, and location of the file (what folder it belongs in). They need to be siblings in the same folder.

meteor keycloak third party

i want to test a keycloak request/response with a keycloak server in a docker file running on my localy machine.
The package Keycloak in atmospherejs doesnt work so i decided to include it to my meteor projekt as a third party library.
I put the library in a public/compatibility/keycloak/keycloak.js
The Autocomplete find it but if i use it then im getting a bug.
Exception while invoking method 'getTestToken' ReferenceError: Keycloak is not defined
But i do not understand it because it is correctly implemented as a thid party library in meteor. Can anybody help me to get this done?
Here I packaged the adapter library for meteor. Have not published it because I need to fork the original library and other stuff. Now you can call KeyCloak() on the client. Here's how I tested it in my router.js:
import { Keycloak } from 'meteor/mutdmour:keycloak'
Router.configure({
waitOn: [
function() {
console.log(Keycloak());
}
]
});
Here's what you can do to replicate what I did with other libraries:
create a package, now you can find it in your packages folder
meteor create --package mutdmour:keycloak
copied over the keycloak.js into packages/keycloak
changed the package.js file to reference the mainModule to run only on the client. This is why you are getting 'window is not defined'. Because it's running on the server. You could try putting that import in a if (Meteor.isClient()){...}
api.mainModule('keycloak.js', 'client');
added an export to package.js
api.export('Keycloak', 'client');
add the word export to the Keycloak definition in keycloak.js
export var Keycloak =
add the package
meteor add mutdmour:keycloak

Downloading PDF file using meteor

We wanted to download PDF files using:
http://username:password#myapp.com/Folder/client.pdf
How can I achieve this using meteor?
I have added the recommendation below to the router.js:
https://github.com/Rebolon/meteor-tuto-routerAndFileDownload/blob/master/tuto-routerAndImage.js
But getting this error on the browser:
Exception in callback of async function: ReferenceError: Npm is not defined
Download File in Meteor
Base on iron router documentation you can use this.
Apache servicng static file
If you want to force to download you can use .htaccess.
Router.js
Router.route('/Folder/:filename', function () {
this.response.end('some file content\n');
}, {where: 'server'});
Download.html
Download File
Why Npm is not defined i appearing.
You must run the router with where: 'server'

Resources