I have a node program running on node12 and I don't have babel in my project because I don't like compiling the code. When I use jest: ^24.9.0 to test my code I get this error message:
Support for the experimental syntax 'classProperties' isn't currently enabled.
Below is the code causes this error. However, it runs very well on node. I have searched this error and many people say to configure the babel for that. I don't really want to bring babel to my project. I don'er understand why jest doesn't work with the syntax which is supported by node?
class Server {
static INTERVAL = 2000;
Related
I previously tested and used worker_threads in my project.
Now when attempting to npm run serve or npm run build I'm getting the following error:
This dependency was not found:
worker_threads
I am running node --version v14.17.2 so I know that worker_threads are supported.
I have even created a clean project with Vue CLI and when adding the following code, I still see the same error.
const {
Worker, isMainThread, parentPort, workerData
} = require('worker_threads');
I've searched extensively, but all of the problems and solutions relate to earlier versions of the node that did not support it.
I'm at a loss as to how to solve this. Suggestions are greatly appreciated.
Edit: I've updated all possible modules in the project in case there might be some sort of conflict, but the problem still persists.
My mistake.
The code I wrote to use worker_threads was originally tested in a pure node.js (sever side) environment. The code ended up being required in a Vue component, which of course is browser based, so of course, worker_threads are not available as they are server side.
A solution would be to make a server API call to the code, or to use something such as threads.js which provides a unified API for worker_threads (sever side) and web workers which are browser based (client side).
I'm writing a NodeJS app, using v10.8.0 and Typescript 3.2.1
TS generates JS code fine, but the code cannot be executed because of the following error:
amdefine with no module ID cannot be called more than once per file
I can see the error comes from the amdefine package, but it is actually triggered by other packages which seem to use AMD modules.
I know that adding something like this to the problematic code solves the issue:
if (typeof define !== 'function') {
var define = require('amdefine')(module)
}
but I obviously cannot edit 3rd party code..
Is there a better way to make Node work with AMD modules?
TS target is ES2016 and it uses commonjs modules. This worked fine before. But now that I have these AMD based dependencies, everything is broken.
Any help would be appreciated!
Thanks in advance.
Solved.
Amdefine has a intercept feature which adds the above code to all AMD modules automatically. This is experimental, but it seems to work.
require('amdefine/intercept');
More info on this here
I have use Webpack for a long time and i always tangled with Webpack configurations. Recently, i try something to make VSCode show intellisense with Webpack and i found out webpack is a function.
That's great because now i can enable intellisense without reading complicated boring documents. But when it runs, it's not wonderful as i respect. The type checking warning wrong. I tried to run webpack({}) in console and it return something like Compiler schemas or default configuration. Although I found another way to enable intellisense using /** #type {webpack.Configuration} */ but still wonder; what does webpack() function really do and do we need to care about it?
Thanks, Sincerely!
webpack function enables a programmatic use of Webpack.
As Webpack Node.js API documentation states,
The imported webpack function is fed a webpack Configuration Object and runs the webpack compiler if a callback function is provided
<...>
If you don’t pass the webpack runner function a callback, it will return a webpack Compiler instance. This instance can be used to manually trigger the webpack runner or have it build and watch for changes, much like the CLI.
It isn't needed in webpack.config.js because this is already handled by Webpack CLI.
I am a complete newbee to web development, and now I am facing a problem that I do not know how to deal with.
I am using the npm package named #uniprank/ngx-file-uploader (https://www.npmjs.com/package/#uniprank/ngx-file-uploader) in my web application, which is developed in Typescript with Angular 4. When compiling it with JIT compilation it works with no problems. However, now I would like to turn my application to production mode, so I tried AOT compilation. When I try to compile my application with the Angular compiler, as it is shown here: https://angular.io/guide/aot-compiler. The message shown is the following:
Unexpected value 'undefined' exported by the module 'FileUploaderModule in /node_modules/#uniprank/ngx-file-uploader/typings/index.d.ts'
I am completely lost at this point. Although I have been looking around in the web, I cannot figure out what means that message and how to fix it.
Any ideas to solve this problem will be appreciated. Thanks.
I have been upgrading my project to use ES7. I have changed some codes, made use of classes.
But there is a problem.
class Example {
change = async (params) => {
const job = await Some.job();
}
}
Everytime I wanted to debug it gives me Unexpected token problem. Even if I run it with Babel, it fails. I know a project where people use this kind of syntax and it works. I could not a valid solution on the internet, a couple github issues but nothing solid, so asking here.
What is the problem here? How should I setup the Babel or the project? Below the error from the console and my config file screenshots.
Just check out this link. Installing Babel V6.x ES7 Async/Await on Node.js v6.2.0 with Nodemon
(You can also check this if you want to install plugin: https://babeljs.io/docs/plugins/transform-async-to-generator/ )
Alternatively search Google "babel async await support" and see the results.
Babel does not give you whole things supported out of the box, you have to make some configurations, installing presets/plugins etc.
In my situation I needed to install stage-0 preset and/or transform plugins to make sure async keywords are supported. In the link above it says stage-3 but you can install stage-0 also, it includes all the plugins up to stage-3.
Babel needs to be documented much better, there is no way you could just get to documentation and set things up. There is not a straight one way Getting started a Project setup that shows you things in an ordered way. Hope they woul add it.