I'm having an issue with vue-loader where it will not recognize es2015 format.
Here are the steps I'm taking:
//initialize the project via vue-cli
vue init webpack-simple && npm i
// start the webpack-dev-server, this npm script is an alias for the command:
// webpack-dev-server --inline --hot
npm run dev
At this point the files are being hosted by webpack-dev-server at localhost:8080 successfully.
When I modify App.vue and add anything es2015 in I get an error from webpack-dev-server:
<template>
<div id="app">
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
data () {
return {
msg: 'Hello Vue!'
}
},
// added this function call for the ready lifecycle hook
ready () => alert('worked')
}
</script>
<style>
body {
font-family: Helvetica, sans-serif;
}
</style>
This made me think that the es2015 preset for babel wasn't installed, but it is definitely in the dev dependencies list along with the transform-runtime:
// truncated package.json
{
...
"scripts": {
"dev": "webpack-dev-server --inline --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"vue": "^1.0.0",
"babel-runtime": "^5.8.0"
},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"cross-env": "^1.0.6",
"css-loader": "^0.23.0",
"file-loader": "^0.8.4",
"json-loader": "^0.5.4",
"url-loader": "^0.5.7",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.0.0",
"vue-loader": "^8.2.1",
"vue-style-loader": "^1.0.0",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0"
}
}
Plus the docs for vue-loader say that es2015 is enabled by default:
There are many cool features provided by vue-loader:
ES2015 enabled by default;
Is there a step or a configuration I'm missing?
Versions:
vue-cli: 2.0.3
npm: 3.8.6
node: 6.0.0
I think it should be
ready: () => alert('worked')
or
ready(){alert('worked')}
Related
hi i will try to learn gulp but at start i have an error in my simple hello world. can anybody help me?
my gulp version is:
CLI version 3.9.0
Local version 4.0.2
my .babelrc file :
{
"presets": [ "#babel/preset-env" ]
}
my gulpfile.babel.js file :
export const hello = (done) => {
console.log('hello');
done();
}
my package.json file :
"name": "meatheme",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"start": "gulp",
"build": "gulp build --prod",
"bundle": "gulp bundle --prod"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.12.3",
"#babel/preset-env": "^7.12.1",
"#babel/register": "^7.12.1",
"babel-loader": "^8.1.0",
"browser-sync": "^2.26.13",
"del": "^5.1.0",
"gulp": "^4.0.2",
"gulp-clean-css": "^4.3.0",
"gulp-if": "^3.0.0",
"gulp-imagemin": "^7.1.0",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.0.0",
"gulp-sass": "^5.0.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-uglify": "^3.0.2",
"gulp-wp-pot": "^2.5.0",
"gulp-zip": "^5.0.2",
"sass": "^1.43.4",
"vinyl-named": "^1.1.0",
"webpack-stream": "^5.2.1",
"yargs": "^15.4.1"
},
"dependencies": {
"#fortawesome/fontawesome-free": "^5.15.1",
"jquery": "^3.5.1",
"normalize.css": "^8.0.1",
"slick-carousel": "^1.8.1"
}
}
and when i run gulp hello is see this in terminal.
[16:47:07] Failed to load external module babel-core/register
[16:47:07] Failed to load external module babel/register
/home/mehdi/Work/Meacodes/Mea template/mea0.1/gulpfile.babel.js:16
import gulp from 'gulp';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
at Liftoff.execute (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:203:12)
at module. Exports (/usr/local/lib/node_modules/gulp/node_modules/flagged-respawn/index.js:51:3)
do you know where is my issue?
I was advised to write "type": "module" to file package.json to the very end of the file
since node otherwise does not consider js files as ES modules, outside of which you still cannot use the import statement)
(in the browser we do modules through the type attribute of the script tag)
I'm trying to set up a React app with Gatsby, and for some reason the ESLint doesn't seem to be fully working properly.
I put the code const test = 4; and left the variable unused, which I would expect to throw an unused-variable error in ESLint, but it does not.
I use VSCode.
This is my eslintrc.json
{
"extends": ["airbnb", "prettier", "prettier/react"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
}
These are the dependencies in my package.json
"dependencies": {
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"gatsby": "^2.24.67",
"gatsby-cli": "^2.12.102",
"gatsby-plugin-material-ui": "^2.1.10",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {
"eslint": "^7.10.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "2.0.5"
},
You need to add the rule in your eslintrc.json file:
"rules":{
"no-unused-vars": "warn",
}
Of course, you can change the warning for your desired behavior. You can check for further details in ESLint docs.
I'm working on a project written in Laravel 5.4 and Vue 2 + Yarn
I'm getting errors the following JS errors in IE (versions 9-11)
Syntax error (line where there is usage in const and arrow functions)
Object doesn't support property or method 'startsWith'
What am I missing ? I wonder if I'm misusing babel or perhaps something else is missing. I'm totally frustrated here because I already spent so much time figuring why nothing work properly in IE when Vue 2 components are involved. Any help or advise here will be highly appreciated !
app.js:
require('./bootstrap');
var Promise = require('es6-promise').Promise;
require('babel-polyfill')
Promise.polyfill();
window.Vue = require('vue');
import Vue2Filters from 'vue2-filters'
import BootstrapVue from 'bootstrap-vue'
my webpack.mix.js (tried to install babel)
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.babel('out.es6.js', 'out.js')
.options({
polyfills: [
'Promise'
]
});
my package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"build": "babel src -d lib"
},
"devDependencies": {
"accounting": "^0.4.1",
"axios": "^0.15.3",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-vue-app": "^1.3.1",
"bootstrap-sass": "^3.3.7",
"cross-env": "^3.2.3",
"jquery": "^3.1.1",
"laravel-mix": "0.*",
"lodash": "^4.17.4",
"vue": "^2.4.2",
"vue-template-compiler": "^2.4.2",
"webpack": "^3.8.1"
},
"dependencies": {
"bootstrap-vue": "^1.0.0-beta.7",
"es6-promise": "^4.1.1",
"vee-validate": "^2.0.0-beta.17",
"vue-events": "^3.0.1",
"vue-strap": "^1.1.37",
"vue2-filters": "^0.1.9",
"vuelidate": "^0.5.0"
}
}
I succeeded to resolve the problem by running the babel code, echoing the results to specific location:
my .bashrc:
{
"presets": ["es2015"]
}
command:
./node_modules/.bin/babel public/js/app.js > public/js/out.js
Then in the layouts files I included public/js/out.js file instead of public/js/app.js
I found tutorials like this: https://medium.com/heresy-dev/getting-started-with-postcss-a-quick-guide-for-sass-users-90c8b675d5f4
(I must really wonder how less i find on the internet about the use of a postcss.json config file.)
and this one: https://www.sitepoint.com/an-introduction-to-postcss/
But all those tutorials didnt worked for me. I use the latest version of postcss and postcss-cli. When i start this script:
"postcss": "postcss --config postcss.json"
then i just get a error:
Input Error: Did not receive any STDIN
When i google for this, i also dont find any solution that helps me.
My package.json:
{
"scripts": {
"postcss": "postcss --config postcss.json"
},
"devDependencies": {
"autoprefixer": "^7.1.6",
"bootstrap-sass": "^3.3.7",
"cssnano": "^3.10.0",
"node-sass": "^4.5.0",
"postcss": "^6.0.13",
"postcss-cli": "^4.1.1",
"postcss-colormin": "^2.2.2",
}
}
My postcss.json:
{
"use": [
"autoprefixer"
],
"input": "public_html/css/",
"output": "public_html/css/min/*.css",
"local-plugins": true,
"watch": false
}
{
"name": "react-redux-starter-kit",
"version": "1.0.0",
"description": "This would be the starter kit for react projects.",
"main": "index.html",
"scripts": {
"start": "rm -rf build/ && rm -rf dist/ && webpack && webpack-dev-server --progress --colors",
"build": "rm -rf build/ && rm -rf dist/ && NODE_ENV=production webpack --config ./webpack.production.config.babel.js --progress"
},
"repository": {
"type": "git",
"url": "git+https://rahulshettyprdxn#bitbucket.org/rahulshettyprdxn/react-devops.git"
},
"keywords": [
"react",
"webpack",
"react-native"
],
"author": "Rahul Shetty",
"license": "MIT",
"homepage": "https://bitbucket.org/rahulshettyprdxn/react-devops#readme",
"devDependencies": {
"babel-core": "^6.5.2",
"babel-eslint": "^5.0.0",
"babel-loader": "^6.2.3",
"babel-plugin-react-transform": "^2.0.0",
"babel-preset-es2015-without-strict": "0.0.2",
"babel-preset-react": "^6.5.0",
"css-loader": "^0.23.1",
"eslint": "^2.2.0",
"eslint-plugin-react": "^4.1.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"html-webpack-plugin": "^2.9.0",
"image-webpack-loader": "^1.6.3",
"node-sass": "^3.4.2",
"react-css-modules": "^3.7.5",
"react-transform-hmr": "^1.0.2",
"sass-loader": "^3.1.2",
"style-loader": "^0.13.0",
"webpack": "^1.12.14",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"bootstrap": "^3.3.6",
"react": "^0.14.7",
"react-bootstrap": "^0.28.3",
"react-dom": "^0.14.7"
}
}
Below is the error that I am receiving:
Parsing error: Unexpected token at line 2 col 8 in Atom editor.
Note that I'm currently getting this error on Windows 10.
ESLint Version:
"eslint": "^2.2.0",
"eslint-plugin-react": "^4.1.0"
I have installed linter-eslint in my Atom editor and Global npm ESLint setting is off.
I am quite confused as the error message is not that descriptive. This in no way is hampering my project but I am quite inquisitive as to why I am getting this error in my editor.
ESLint is for validating JavaScript, not JSON.
From the website:
ESLint
The pluggable linting utility for JavaScript and JSX
[emphasis mine]
(You can try your code on the online demo here, and you get the same error)
If you want to use ESLint on a JSON file, you could use a package like eslint-plugin-json.