Parcel and react 18 project set up error. #parcel/transformer-js: Unexpected token `)`. Expected this, import, async, function - parceljs

Server running at http://localhost:1234
🚨 Build failed.
#parcel/transformer-js: Unexpected token ). Expected this, import, async, function, [ for array literal, { for object literal, # for
decorator, function, class, null, true, false, number, bigint, string, regexp, ` for template literal, (, or an identifier
/home/sizzions/Desktop/Projects/web app/WenApp/src/index.js:5:19
4 | const root = createRoot(container); // createRoot(container!) if you use TypeScript
5 | root.render(/);
| ^
`import { createRoot } from 'react-dom/client';
import App from './App';
const container = document.getElementById('app');
const root = createRoot(container); // createRoot(container!) if you use TypeScript
root.render(<App/>);`

FWIW, I ran into this for a few minutes until I realized react wasn't no longer in my package.json file. After adding react 18 back in I was good to move on to my next error. :)

Related

Yocto - git revision in the image name

By default Yocto adds build timestamp to the output image file name, but I would like to replace it by the revision of my integration Git repository (which references all my layers and configuration files). To achieve this, I put the following code to my image recipe:
def get_image_version(d):
import subprocess
import os.path
try:
parentRepo = os.path.dirname(d.getVar("COREBASE", True))
return subprocess.check_output(["git", "describe", "--tags", "--long", "--dirty"], cwd = parentRepo, stderr = subprocess.DEVNULL).strip().decode('UTF-8')
except:
return d.getVar("MACHINE", True) + "-" + d.getVar("DATETIME", True)
IMAGE_VERSION = "${#get_image_version(d)}"
IMAGE_NAME = "${IMAGE_BASENAME}-${IMAGE_VERSION}"
IMAGE_NAME[vardepsexclude] = "IMAGE_VERSION"
This code works properly until I change Git revision (e.g. by adding a new commit). Then I receive the following error:
ERROR: When reparsing /home/ubuntu/yocto/poky/../mylayer/recipes-custom/images/core-image-minimal.bb.do_image_tar, the basehash value changed from 63e1e69797d2813a4c36297517478a28 to 9788d4bf2950a23d0f758e4508b0a894. The metadata is not deterministic and this needs to be fixed.
I understand this happens because the image recipe has already been parsed with older Git revision, but why constant changes of the build timestamp do not cause the same error? How can I fix my code to overcome this problem?
The timestamp does not have this effect since its added to vardepsexclude:
https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-metadata.html#variable-flags
[vardepsexclude]: Specifies a space-separated list of variables that should be excluded from a variable’s dependencies for the purposes of calculating its signature.
You may need to add this in a couple of places, e.g.:
https://git.yoctoproject.org/poky/tree/meta/classes/image-artifact-names.bbclass#n7
IMAGE_VERSION_SUFFIX ?= "-${DATETIME}"
IMAGE_VERSION_SUFFIX[vardepsexclude] += "DATETIME SOURCE_DATE_EPOCH"
IMAGE_NAME ?= "${IMAGE_BASENAME}-${MACHINE}${IMAGE_VERSION_SUFFIX}"
After some research it turned out the problem was in this line
IMAGE_VERSION = "${#get_image_version(d)}"
because the function get_image_version() was called during parsing. I took inspiration from the source file in aehs29's post and moved the code to the anonymous Python function which is called after parsing.
I also had to add vardepsexclude attribute to the IMAGE_NAME variable. I tried to add vardepvalue flag to IMAGE_VERSION variable as well and in this particular case it did the same job as vardepsexclude. Mentioned Bitbake class uses both flags, but I think in my case using only one of them is enough.
The final code is below:
IMAGE_VERSION ?= "${MACHINE}-${DATETIME}"
IMAGE_NAME = "${IMAGE_BASENAME}-${IMAGE_VERSION}"
IMAGE_NAME[vardepsexclude] += "IMAGE_VERSION"
python () {
import subprocess
import os.path
try:
parentRepo = os.path.dirname(d.getVar("COREBASE", True))
version = subprocess.check_output(["git", "describe", "--tags", "--long", "--dirty"], cwd = parentRepo, stderr = subprocess.DEVNULL).strip().decode('UTF-8')
d.setVar("IMAGE_VERSION", version)
except:
bb.warning("Could not get Git revision, image will have default name.")
}
EDIT:
After some research I realized it's better to define a global variable in layer.conf file of the layer containing the recipes referencing the variable. The variable is set by a python script and is immediately expanded to prevent deterministic build warning:
layer.conf:
require conf/image-version.py.inc
IMAGE_VERSION := "${#get_image_version(d)}"
image-version.py.inc:
def get_image_version(d):
import subprocess
import os.path
try:
parentRepo = os.path.dirname(d.getVar("COREBASE", True))
return subprocess.check_output(["git", "describe", "--tags", "--long", "--dirty"], cwd = parentRepo, stderr = subprocess.DEVNULL).strip().decode('UTF-8')
except:
bb.warn("Could not determine image version. Default naming schema will be used.")
return d.getVar("MACHINE", True) + "-" + d.getVar("DATETIME", True)
I think this is cleaner approach which fits BitBake build system better.

Babel: replaceWithSourceString giving Unexpected token (1:1)

I am trying to replace dynamically "import" statements.
Here is an example that checks if the import ends with a Plus.
module.exports = function(babel) {
return {
visitor: {
ImportDeclaration: function(path, state) {
// import abc from "./logic/+"
if( ! path.node.source.value.endsWith("/+"))
return;
path.replaceWithSourceString('import all from "./logic/all"')
}
}
}
}
This gives an error of
SyntaxError: src/boom.js: Unexpected token (1:1) - make sure this is an expression.
> 1 | (import all from "./logic/all")
The problem is that replaceWithSourceString is wrapping the string in rounded braces.
If I change the replaceWithSourceString to
path.replaceWithSourceString('console.log("Hi")')
and this works.. ¯_(ツ)_/¯
Any and all help you be great
replaceWithSourceString should really be avoided, because it is just not a very good API, as you are seeing. The recommended approach for creating ASTs to insert into the script is to use template. Assuming this is for Babel 7.x, you can do
const importNode = babel.template.statement.ast`import all from "./logic/all"`;
path.replaceWith(importNode);

Syntax error in db.collection.save()

I am trying MongoDB for first time but I am stuck on the following syntax error: unexpected token illegal. I checked it and it looks OK. I found similar a problem on StackOverflow but that is for a different error. What am I doing wrong?
Here is my script:
db.student.save({"_id":ObjectId(5983548781331adf45ec7),"name":"replaced","age":55})
The problem is here : ObjectId(5983548781331adf45ec7)
ObjectId accepts a string of 24 hex digits.
ObjectId("<24 hex digits here>")
E.g. ObjectId("0123456789abcdef01234567")
If you are using a backend source code such as groovy (with Grails GORM), you can try the following script which is very clean and readable:
def studentFromDB = db.student.findById("5983548781331adf45ec7")
studentFromDB.name = "replaced"
studentFromDB.age = 55
studentFromDB.save(flush: true, failOnError: true)
If you use it directly onto the mongo you should use the MongoDB update, for example:
db.student.update(
{"_id":ObjectId(5983548781331adf45ec7) },
{
name: "replaced",
age: 55
},
{ upsert: true }
)
I fixed it...the error is i missed quotes inside 'ObjectId'
the corrected script is `db.student.save({"_id":ObjectId("57fcf46763ecce707f071884"),"name":"rep_dsave","age":37}).
Thanks 4J41 and rotemy
`

Using Trello REST in Ionic 2 - Error TS2304 Cannot find name 'Trello'

being a newbee to the ionic 2 and Trello REST interface I need help please:
As per the Trello.com site (https://developers.trello.com/get-started/start-building) I have:
Added under the html line in the index.html ie: before the body as they ask, the following and replaced the AppKey in my code:
< script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
< script src="https://api.trello.com/1/client.js?key=[AppKey]"></script>
Added code to add a card as per their example:
var myList = 'myIDLIST';
var creationSuccess = function(data) {
console.log('Card created successfully. Data returned:' + JSON.stringify(data));
};
var newCard = {
name: 'New Test Card',
desc: 'This is the description of our new card.',
// Place this card at the top of our list
idList: myList,
pos: 'top'
};
Trello.post('/cards/', newCard, creationSuccess);
However I get a typescript error:
TypeScript error: C:/workspace/...etc..../service.ts(66,9): Error TS2304: Cannot find name 'Trello'.
I thought Trello should be available to other modules since its declared in the index.html
Any help appreciated.
The Trello object might exist at runtime, but the Typescript compiler doesn't know about it, so it reports the errors. You have to provide the declaration files or simply tell the compiler that it should expect a global Trello object. For that put this line of code to the beginning of every file that uses the Trello object.
declare var Trello: any;
You can also use the node-trello package and import it directly.

how to compare expected value to be in the list [duplicate]

One of my test expects an error message text to be one of multiple values. Since getText() returns a promise I cannot use toContain() jasmine matcher. The following would not work since protractor (jasminewd under-the-hood) would not resolve a promise in the second part of the matcher, toContain() in this case:
expect(["Unknown Error", "Connection Error"]).toContain(page.errorMessage.getText());
Question: Is there a way to check if an element is in an array with jasmine+protractor where an element is a promise?
In other words, I'm looking for inverse of toContain() so that the expect() would implicitly resolve the promise passed in.
As a workaround, I can explicitly resolve the promise with then():
page.errorMessage.getText().then(function (text) {
expect(["Unknown Error", "Connection Error"]).toContain(text);
});
I'm not sure if this is the best option. I would also be okay with a solution based on third-parties like jasmine-matchers.
As an example, this kind of assertion exists in Python:
self.assertIn(1, [1, 2, 3, 4])
Looks like you need a custom matcher. Depending on the version of Jasmine you are using:
With Jasmine 1:
this.addMatchers({
toBeIn: function(expected) {
var possibilities = Array.isArray(expected) ? expected : [expected];
return possibilities.indexOf(this.actual) > -1;
}
});
With Jasmine 2:
this.addMatchers({
toBeIn: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var possibilities = Array.isArray(expected) ? expected : [expected];
var passed = possibilities.indexOf(actual) > -1;
return {
pass: passed,
message: 'Expected [' + possibilities.join(', ') + ']' + (passed ? ' not' : '') + ' to contain ' + actual
};
}
};
}
});
You'll have to execute this in the beforeEach section on each of your describe blocks it's going to be used in.
Your expect would look like:
expect(page.errorMessage.getText()).toBeIn(["Unknown Error", "Connection Error"]);
The alternative solution is to use .toMatch() matcher with Regular Expressions and specifically a special character | (called "or"), which allows to match only one entry to succeed:
expect(page.errorMessage.getText()).toMatch(/Unknown Error|Connection Error/);
To me, the work-around that you identified is the best solution. However, we should not forget that this is an asynchronous execution and you might want to consider Jasmine's asynchronous support.
Then, your test will look like the following one:
it('should check item is in array', function(done){ //Note the argument for callback
// do your stuff/prerequisites for the spec here
page.errorMessage.getText().then(function (text) {
expect(["Unknown Error", "Connection Error"]).toContain(text);
done(); // Spec is done!
});
});
Note: If you don't pass this done argument to the spec callback, it is going to run to completion without failures, but no assertions are going to be reported in the execution results for that spec (in other words, that spec will have 0 assertions) and it might lead to confusions.