Babel helper-module-transforms runs into undefined is not a function - ecmascript-6

I am running mocha unit tests that are written in ES6. Using Babel to run the tests and running into a very bizarre error. This happens as soon as I import something from multiple test scripts. If ES6 Import is used from only one single test script everything works fine.
Here is a snippet of what the error looks like and I have a video that shows exactly how it can be reproduced.
/node_modules/#babel/helper-module-transforms/lib/normalize-and-load-metadata.js:37:52
TypeError: undefined is not a function
https://www.youtube.com/watch?v=jm0p1ttwFZc
Here is the git repo of the problem.
npm install
in /server
https://github.com/jiminssy/BabelProblem

This is because you are using https://www.npmjs.com/package/collections. It replaces many ES6-standard libraries with its own versions that do not conform to the standard behaviors that Babel is expecting and relies on to compile files.
Your option option would be to drop that library, or drop #babel/register. I'd recommend dropping the library since it seems to be extremely poorly designed.

Related

Fatal error (13): No program entry point with XDS Modula-2?

I'm using the current bundled binaries from https://github.com/excelsior-oss/xds (as of 12/6/2020) with just the most basic Hello World MOD file:
MODULE HelloWorld;
FROM STextIO IMPORT WriteLn, WriteString;
BEGIN
WriteString("Hello, World!");
WriteLn;
END HelloWorld.
xc HelloWorld.mod works fine for compiling it to object. However, I'm not clear on the exact syntax for xlink on a standalone MOD file. xlink HelloWorld.obj will at least get it to try with my object file, but as the error shows, it doesn't know the entrypoint. I've tried setting the entry point with the /ENTRY switch, but no luck doing it by module name. I've also tried setting the /SYS to console, but again, no luck there.
I feel there's some trivial linker option or program directive needed, but I'm just not finding it via Google...
To build a binary, use: xc =a =make HelloWorld.mod
The above is found in https://github.com/excelsior-oss/xds/blob/master/Sources/Doc/Comp/src/usage.tex .
It is unfortunate that XDS did not put PDFs of their documentation on github. I suggest building the documentation from their LaTeX files.
Edit: I since learnt that the Wayback Machine has archived the XDS documentation here: https://web.archive.org/web/20060705213825/http://www.excelsior-usa.com/xdsdoc.html

PhpStorm can't resolve package import even though it exists (react-router-dom)

I am using React (16.12.0) with PhpStorm (2019.3.1).
The package I am importing is react-router-dom (5.1.2)
I will write the following import:
import { NavLink, Switch } from "react-router-dom";
Both packages are imported properly by webpack/babel and the page renders properly when I use both Switch and NavLink.
However purely from the IDE-perspective, I get a warning about Switch: Cannot resolve symbol 'Switch'
It is weird because it is obviously there, and I checked in /node_modules/react-router-dom and Switch.js is there.
Strangely on previous versions of PhpStorm (before several updates and plugin imports and other changes), the Switch import was accurately found by PhpStorm.
I have not updated react-router-dom recently and am using its latest stable build.
Any ideas as to why it might be missing Switch?
EDIT:
I have realized it may be because PhpStorm is having difficulty importing a commonJS module.
I tried changing the Javascript compilation method from React JSX to ECMA 6. That didn't work.
I also tried importing some build libraries for react-router-dom, and that worked for recognizing the Route import strangely but not Switch.
I also tried invalidating the PhpStorm cache and restarting the app, but that didn't work either.
EDIT 2:
Per an answer, I have tried to use option+enter (alt+enter on windows) while my cursor is within react-router-dom to try to install a typescript package, but I don't get the same suggested action as shown on the JetBrains website: https://www.jetbrains.com/help/webstorm/configuring-javascript-libraries.html
All it suggests is switching single quotes to double quotes.
Also I have already installed #types/react-router-dom. Perhaps there is another one that I am missing?
EDIT 3:
The correct answer was to install #types/react-router. For some reason #types/react-router-dom is deceivingly NOT what solves this.
node_modules/react-router-dom/esm/react-router-dom.js exports BrowserRouter, HashRouter, Link and NavLink, but doesn't export Switch, it's not explicitly defined there.
For better completion/type hinting, you can install Typescript stubs for the package: put cursor on "react-router-dom" in import statement, hit Alt+Enter, choose Install TypeScript definitions for better type information::
See https://www.jetbrains.com/help/webstorm/2019.3/configuring-javascript-libraries.html#ws_jsconfigure_libraries_ts_definition_files

Configuring Jest + Enzyme to run tests in PhpStorm?

I'm following the TypeScript create-react-app tutorial and I managed to get Jest + enzyme working through the command line, but I'd also like to be able to test single functions and whatnot inside of PhpStorm. However I keep getting the following error when running through PhpStorm:
Error: An error occurred while adding the reporter at path "/snap/phpstorm/36/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js".Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
What should my test setup/configuration look like? I can't seem to find any examples in the PhpStorm Docs or otherwise. Thanks!

Closuer compiler having error like "namespace never provided'

I am compiling ES6 modules into ES3 via clouser compiler but getting error,
What am i doing wrong?
see this issue i've posted on github
https://github.com/google/closure-compiler/issues/2139
fixed is using **/*.js
(which cause all files be included in compiler)

Prevent Karma & Protractor from Linting Files

Is there any way to stop Karma &/or Protractor from linting files in the stream passed to it? We are using gulp, but this could probably apply to other automation tools/environments. While I am sure they are just trying to be helpful, this clogs up our console and is redundant. Worse, it can be confusing to see the same error twice.
Here is an example task:
var karma = require('karma').server;
var spawn = require('child_process').spawn;
gulp.task('tests', function() {
karma.start({
files = 'my/unit/test/files/*.spec.js',
singleRun: true
}, function(error) {
if(error) {
console.log(error);
}
});
spawn('protractor', ['--specs=my/e2e/test/files/*.e2e.js'],
{stdio: 'inherit'}
);
});
If the file "my/e2e/test/files/test.e2e.js" exists & has a JSHint error, Protractor will report the error, whether or not you also run gulp-jshint or something else.
As an example, if the file "my/e2e/test/files/test.e2e.js" looked like this:
describe('some test', function() {
);
The output of gulp tests might look like this:
... some setup...
Protractor:
[09:32:30] An error occurred during the end-to-end testing run
[09:32:30] my/e2e/test/files/test.e2e.js:3
);
^
... some Protractor tests ...
... some Karma tests ...
If the file "my/unit/test/files/test.spec.js" exists & has a JSHint error, Karma will report this error, and it will not run. For example, if the file "my/unit/test/files/test.spec.js" looks the same as "my/e2e/test/files/test.e2e.js" above, the output of gulp tests may look like this:
...some setup...
Karma (I think):
PhantomJS 1.9.8 (Linux) ERROR
SyntaxError: Parse error
at my/unit/test/files/test.spec.js
SUMMARY:
✔ 0 tests completed
...some protractor tests...
It seems that Karma fails the task and does not run if there is an error in the spec files passed to it, and Protractor will report the error but still run, and will report the error in the tasks contained in the errored file. I would rather both streams run, both sets of tests run completely, and perhaps report syntax errors in the test output. However, they should not report the syntax errors before the tests run, or after, because we already have gulp-jshint for linting files. This is just redundant, and it is twice-redundant, in the case of Protractor, if you have a linting plugin already.
So, back to my question: Is there any way to prevent Karma &/or Protractor from linting in their respective streams, separately from the output of the tests? Is there any way to get access to their respective error reporters, without changing their source code? I could always kill them both on any errors before they run, but I may want to run the tests anyway, and I would definitely want to run the other testing framework (for example, run Karma if there are syntax errors in .e2e.js files).
The errors that both Protractor and Karma are Error that the Javascript Engines (the browser you're using for testing) are shouting to you.
Karma and Protractor are not "linting" anything themselves.
To debug the issue in Karma follow these steps:
Add a regular browser to the karma configuration: instead of PhantomJS use either Chrome or Firefox
Start the karma server (not the runner): in your Gulpfile.js change singleRun from true to false.
Once karma and your browser have started you should have a similar window:
Now click on the DEBUG button, it will open a new tab, where you can open the Dev Tools (in case you're using Chrome):
In the Javascript console now you should be able to see that Syntax Error "Karma is reporting" (effectively karma is just repeating what Phantom is trying to say)
Solve those issues and then try to run again in the browser.
Once everything has been fixed switch back to PhantomJS and singleRun: true.
It's not about linting, it's about having understandable/parsable code.
Your example file "my/e2e/test/files/test.e2e.js" is not well written, you're missing function close. Some errors can be "understood" by karma, protractor or your browser, like a missing semicolon.
But errors like not closing a function breaks the parsing of the file and parser won't understand what you mean.
Having such code in a website would break the rendering and result in not running.