So I was running yarn command and got this error no matter what project i was in.
error An unexpected error occurred: "/Users/name/package.json: Unexpected token \\ in JSON at position 1".
Trace: SyntaxError: /Users/name/package.json: Unexpected token \\ in JSON at position 1 at JSON.parse () at /usr/local/Cellar/yarn/1.22.5/libexec/lib/cli.js:1625:59 at Generator.next () at step (/usr/local/Cellar/yarn/1.22.5/libexec/lib/cli.js:310:30) at /usr/local/Cellar/yarn/1.22.5/libexec/lib/cli.js:321:13
#!/usr/bin/env node
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/
Package.json:
{
"name": "vue-cli-sample",
"version": "0.1.0",
"private": false,
"description": "Sample project generated using Vue-CLI",
"author": "Irfan Maulana <github.com/mazipan>",
"scripts": {
"serve": "./node_modules/.bin/cross-env NODE_ENV=development vue-cli-service serve --host localhost",
"build": "./node_modules/.bin/cross-env NODE_ENV=production vue-cli-service build",
"test": "./node_modules/.bin/cross-env NODE_ENV=test jest --coverage",
"lint": "vue-cli-service lint",
"dev": "npm run serve",
"dist": "npm run dist",
"test:unit": "npm run test"
},
"dependencies": {
"bootstrap-vue": "^2.16.0",
"intro.js": "^2.9.3",
"parse-json": "^2.2.0",
"register-service-worker": "1.6.2",
"vue": "2.6.10",
"vue-introjs": "^1.3.2",
"vue-router": "3.0.7",
"vuex": "3.1.1",
"webpack": "^4.44.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "3.9.2",
"@vue/cli-plugin-eslint": "3.9.2",
"@vue/cli-plugin-pwa": "3.9.0",
"@vue/cli-service": "3.9.2",
"@vue/eslint-config-standard": "4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.2",
"babel-jest": "24.8.0",
"cross-env": "5.2.0",
"eslint": "6.0.1",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-node": "9.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.0",
"eslint-plugin-vue": "5.2.3",
"jest": "24.8.0",
"jest-serializer-vue": "2.0.2",
"jest-transform-stub": "2.0.0",
"jest-watch-typeahead": "0.3.1",
"less": "3.9.0",
"less-loader": "5.0.0",
"lint-staged": "9.2.0",
"vue-jest": "3.0.4",
"vue-template-compiler": "2.6.10",
"webpack-dev-server": "3.7.2"
},
"resolutions": {
"webpack-dev-server": "3.7.2"
},
"bugs": {
"url": "https://github.com/mazipan/vue-cli-sample/issues"
},
"gitHooks": {
"pre-commit": "lint-staged"
},
"license": "MIT",
"lint-staged": {
"*.{js,vue}": [
"vue-cli-service lint --fix",
"git add"
]
},
"repository": {
"type": "git",
"url": "https://github.com/mazipan/vue-cli-sample.git"
}
}
My yarn version v1.22.5 I have both node version 12 and 15 it uses 15 as default
I found the solution. The problem was with my /Users/name/package.json. To solve it you need to erase your node modules and package.json. Then you need to do npm install, npm install yarn. For my case i did this in /Users/[name]/ folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.