How To Use Babel Polyfill for Promises? - axios

Hello I am new to using Babel to transpile and polyfill my code to work for older browsers like Edge and IE. I am currently having an issue with polyfilling my code for Promises. I check in Edge and the error I am receiving is:
Error in created hook: "TypeError: Object doesn't support property or
method 'finally'
So the issue is with the finally method in my Vue app. In my app I am using Axios to get data from an API.
So I was going through the steps here: https://babeljs.io/setup.html#installation under the CLI instructions. My package.json file currently looks like so:
{
"name": "job-filtering",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.2.2",
"#babel/plugin-transform-regenerator": "^7.0.0",
"#babel/preset-env": "^7.2.3"
},
"dependencies": {
"#babel/polyfill": "^7.2.5"
}
}
and my .babelrc file looks like:
{
"presets": ["#babel/preset-env"],
"plugins": ["#babel/plugin-transform-regenerator"]
}
and so when I use npm run build in my command line it does transpile my code for what it can, but it does not polyfill things like the finally method in my promise.
I've been trying to search to find an answer, but I can't seem to find anything that is what I'm looking for.
I tried adding:
import 'babel/polyfill';
to the top of my JS file, but that then spit out an error. I know it's probably something small that I'm missing to allow babel to polyfill my JS, but I can't seem to find a solution.

Related

Why is syntax highlighting not showing for my custom extension in VS Code?

I am trying to create a custom language-extension for VS Code. I was mostly following the instructions given here and here.
When I run the extension in the Extension Development Host by hitting F5, everything works fine. As soon as I try to install my extension and use it in VS Code, it does no longer.
From here I gathered that I have three options of installing my extension
bundle my extension to a vsix with vsce and install it from within VS Code
install the vsix package from command line with code --install-extension myExt.vsix
copy the content to a folder in %userprofile%\.vscode\extensions
All three options give the same result: syntax highlighting does not work for keywords, etc. but it does work for comments. Using the Scope Inspector I can see that all the tokens are correctly deteced and categorized, so the extension seems to be basically working, but code is not highlighted (again, except for comments, weirdly).
The only clue I get when I install via command line is
Installing extensions...
(node:34352) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Extension 'vscode-knitout.vsix' was successfully installed.
but I doubt that this has got anything to do with the problem.
This here is my package.json file:
{
"name": "vscode-myLanguage",
"displayName": "myLanguage",
"description": "myLanguage language extension for VS Code",
"version": "0.0.1",
"publisher": "me",
"author": {
"name": "name"
},
"icon": "images/icon.png",
"galleryBanner": {
"color": "#C80000",
"theme": "dark"
},
"engines": {
"vscode": "^1.53.0"
},
"license": "SEE LICENSE IN LICENSE.txt",
"repository": {
"type": "git",
"url": "https://some.git.url"
},
"homepage": "https://our.website",
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "myLanguage",
"aliases": ["myLanguage", "myLanguage"],
"extensions": [".m",".myLanguage"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "myLanguage",
"scopeName": "source.myLanguage",
"path": "./syntaxes/myLanguage.tmLanguage.json"
}],
"themes": [
{
"label": "myLanguage-dark",
"uiTheme": "vs-dark",
"path": "./themes/myLanguage-vs-dark-color-theme.json"
}
]
}
}
When I run via Extension Development Host, the Scope Inspector correctly recognizes the language and textmate scopes and respective theme rule for 'foreground'. When I run VS Code with the extension installed/copied, the Scope Inspector says "No theme selector" for 'foreground', but everything else (scope, language) looks correct.
What is the problem here? Is there a very simple example somewhere for a reference?

TS lint plugin for VS code doesn't track closed files

I'm using VSCode 1.17.2, and using tslint plugin with it to track lint errors. As of now it is working fine with opened files and showing errors on files with red marker and giving error in problems tab. But it is not tracking closed files. Am I missing any configuration? Currently I am using default configuration.
See the documentation for the extension:
The extension lints an individual file only. If you want to lint your
entire workspace or project and want to see the warnings in the
Problems panel, then you can:
use gulp that or define a script inside the package.json that runs
tslint across your project.
define a VS Code task with a problem matcher
that extracts VS Code warnings from the tslint output.
For example, here is an excerpt from a package.json file that defines
a script to run tslint:
{
"name": "tslint-script-demo",
"version": "1.0.0",
"scripts": {
"lint": "tslint tests/*.ts -t verbose"
},
"devDependencies": {
"typescript": "^2.2.2",
"tslint": "^5.0.0" }
}
Next, define a Task which runs the npm script with a problem matcher
that extracts the tslint errors into warnings.
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "lint",
"problemMatcher": {
"base": "$tslint5",
"fileLocation": "relative"
}
}
]
}
Finally, when you then run the tslint task you will see the warnings produced by the npm script in the Problems panel and you can
navigate to the errors from there.
Here is the complete setup example setup.

Configure Visual Studio Code to have a default Build Task based on file extension

I would like to know if there is a way to define a default Build Task for VSCode depending on file extension.
When working in some folder of Python code, I define the following Build Task:
{
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"showOutput": "always",
"args": ["${file}"]
}
Then if next time I go to another Python folder, I have to redefine it again.
Is it possible to configure VSCode in such a way that if it detects the current file as a Python script, then it will automatically define the above Build Task?
Thank you in advance for your help!
Update for latest vscode
The following will create a default "build" script, so you can use the keyboard shortcut to build your project. (Below for a javascript project, but shows general outline for other languages/projects.)
(1) Assuming you have a script named "build.js" at the root of your project.
(2) Create a file named "tasks.json" in root of project (workspace) with the following contents:
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "mybuildscript", // use same name as in package.json
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
(3) In your package.json, add "scripts" as:
// package.json
{
"name": "my",
"version": "1.0.0",
"description": "",
"scripts": {
"mybuildscript": "node ./build.js"
},
"dependencies": {
"myfs": "^1.0.22"
}
}
I created a rudimentary vscode extension that does all this for you:
https://marketplace.visualstudio.com/items?itemName=gieson.make-build-task
The extension isn't perfect (doesn't cover all the possible ways a project/workspace can be configured), but it's a good starting point.
Here's the repo:
https://github.com/bobtherobot/make-build-task
This is possible, but it requires writing an extension (unless somebody has already written one with a tasks provider for Python). Since 1.14.0, there's a new API which allows extensions to dynamically provide tasks. Check out the Task Provider Example.
Alternatiely, the Code Runner extension probably does the trick in this case as well. It doesn't use the Tasks system though.

How do I use .babelrc to get babel-plugin-import working for antd?

I'm new to react, babel, and antd.
I installed react and started a project using create-react-app.
I installed antd (ant.design). It suggests using babel-plugin-import, so I installed that too.
If I interpret it right, the usage documentation for babel-plugin-import says to put this in a .babelrc file:
{
"plugins": [
["import", {
"libraryName": "antd",
"style": true
}]
]
}
I'm having trouble getting it to work. My web console still has the warning:
You are using a whole package of antd, please use
https://www.npmjs.com/package/babel-plugin-import to reduce app bundle
size.
I didn't have a .babelrc file in my project's directory, so I created one with the above contents and restarted my server (npm start). That didn't work, so I created one in myProject/node_modules/babel_plugin_import but that doesn't work either.
Where is that code snippet supposed to go?
At the bottom of https://github.com/ant-design/babel-plugin-import it says
babel-plugin-import will be not working if you add the library in
webpack config vender.
But I don't know what that means.
I asked another question here: How to get antd working with app created via create-react-app?
Maybe this problem has something to do with my project created via create-react-app??
[Update 2018-02-06: The answer is still correct, but there is a better alternative now, which is to use react-app-rewired. This is also documented in the link.]
You need to follow the instructions in https://ant.design/docs/react/use-with-create-react-app#Import-on-demand to a T.
You should not create ant .babelrc files or similar. When using CRA all babel config is handled inside the webpack config files.
First clean up the config files you created, and make sure you have babel-plugin-import installed.
Then eject your app: npm run eject
This will give you a config folder with 2 webpack config files for dev/prod environments.
Open those files and locate the place where you need to insert the plugins property as documented on the instructions page.
Just add what babel-plugin-import documentation says, but remember if you're using CRA, you cannot change babel configuration directly without ejecting the project.
If you don't want to eject, you can use #craco/craco, and put the babel configuration inside of it like this:
/* craco.config.js */
module.exports = {
babel: {
presets: [],
plugins: [
[
"import",
{
libraryName: "antd",
style: true, // or 'css'
},
],
],
loaderOptions: {
/* Any babel-loader configuration options: https://github.com/babel/babel-loader. */
},
},
};
Dont forget to change your scripts (more details in craco docs):
/* package.json */
"scripts": {
- "start": "react-scripts start",
+ "start": "craco start",
- "build": "react-scripts build",
+ "build": "craco build"
- "test": "react-scripts test",
+ "test": "craco test"
}

Why don't my nuget versions match

I get this warning building my asp.net core project on teamcity, and also appears as a warning in visual studios:
Dependency specified was Foo.Client >= 1.0.0-* but ended up with Foo.Client 1.0.25523.
I don't understand why this doesn't match. I can't seem to find any documentation on how to make these wildcard strings.
1.0.25523 is a copy a replace operation I do on my build server to reflect the build number. It's not something I'd like to directly reference, I'm just confused as to why my 1.0.0-* isn't accepting something that looks just to differ by patch version.
My package config looks something like this:
{
"version": "1.0.0-*",
"dependencies": {
"Foo.Bar.Client": "1.0.0-*",
},
"frameworks": {
"net46": {
"dependencies": {
"Foo": {
"target": "project"
}
},
"frameworkAssemblies": {
}
}
}
}
And then the substitution is made here and in the Foo.Bar.Client project.json to change "version": "1.0.0-*" to "version": "1.0.25523"
There should be a *.nuspec file for your project, which will have the information about which package version you're using. From your error message, it seems that the package version in this file is 1.0.0 whereas you'll want to change this to 1.0.25523 I think.
You can also check here for some more information.