Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors of Unexpected token in JSON at position XXX while parsing near

I npm install on a directory with a package.json for my company project. However, it keeps giving me various errors of Unexpected token in JSON at position....

I have done npm cache clean --force, npm cache verify etc. as suggested by When I run `npm install`, it returns with `ERR! code EINTEGRITY` (npm 5.3.0)

However, the issue still persists. I do not configure proxy though as my machine is not on any corporate proxy.

Anyway, I attach the npm log content and package.json file content for your reference. Please kindly help to advise me what's wrong and how to resolve this issue.

npm log:

122 silly pacote range manifest for array-includes@^3.1.1 fetched in 64ms
123 http fetch GET 304 https://registry.npmjs.org/typescript 459ms (from cache)
124 silly pacote range manifest for popper.js@^1.14.1 fetched in 109ms
125 warn deprecated [email protected]: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
126 silly fetchPackageMetaData error for typescript@^3.8.3 Unexpected token  in JSON at position 831531 while parsing near '...k+EIAF5TJm/AB3lmH1Ƃ�,Xj��ZY��x4YSZvSI...'
127 http fetch GET 304 https://registry.npmjs.org/array.prototype.flat 96ms (from cache)
128 silly pacote range manifest for array.prototype.flat@^1.2.3 fetched in 99ms
129 http fetch GET 304 https://registry.npmjs.org/contains-path 94ms (from cache)
130 silly pacote range manifest for contains-path@^0.1.0 fetched in 95ms
131 http fetch GET 304 https://registry.npmjs.org/debug 85ms (from cache)
132 http fetch GET 304 https://registry.npmjs.org/doctrine 75ms (from cache)
133 silly pacote range manifest for debug@^2.6.9 fetched in 89ms
134 silly pacote version manifest for [email protected] fetched in 79ms
...
307 http fetch GET 304 https://registry.npmjs.org/rxjs 71ms (from cache)
308 silly fetchPackageMetaData error for rxjs@^6.6.0 Unexpected token    in JSON at position 133105 while parsing near '...\r\n-----END PGP8'�� C��m�4���
r\n"},"e...'
309 silly pacote range manifest for through@^2.3.6 fetched in 60ms
310 http fetch GET 304 https://registry.npmjs.org/deep-is 51ms (from cache)
...
479 silly pacote range manifest for typescript-eslint-parser@^18.0.0 fetched in 9ms
480 silly resolveWithNewModule [email protected] checking installable status
481 http fetch GET 304 https://registry.npmjs.org/typescript 67ms (from cache)
482 silly fetchPackageMetaData error for typescript@^3.8.3 Unexpected token  in JSON at position 831531 while parsing near '...k+EIAF5TJm/AB3lmH1Ƃ�,Xj��ZY��x4YSZvSI...'
483 timing stage:rollbackFailedOptional Completed in 1ms
484 timing stage:runTopLevelLifecycles Completed in 2633ms
485 silly saveTree [email protected]
...
485 silly saveTree ├── [email protected]
485 silly saveTree └── [email protected]
486 verbose stack SyntaxError: Unexpected token  in JSON at position 831531 while parsing near '...k+EIAF5TJm/AB3lmH1Ƃ�,Xj��ZY��x4YSZvSI...'
486 verbose stack     at JSON.parse (<anonymous>)
486 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
486 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
486 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
487 verbose cwd /home/rugrat/Projects/aleng/ui/includes
488 verbose Linux 4.4.0-189-generic
489 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "install"
490 verbose node v10.22.0
491 verbose npm  v6.14.8
492 error Unexpected token  in JSON at position 831531 while parsing near '...k+EIAF5TJm/AB3lmH1Ƃ�,Xj��ZY��x4YSZvSI...'
493 verbose exit [ 1, true ]

Package.json:

{
  "name": "typescript-type-definitions",
  "version": "1.0.0",
  "description": "Type definitions for TypeScript",
  "main": "typescript/main.js",
  "dependencies": {},
  "devDependencies": {
    "@types/bootbox": "^4.4.36",
    "@types/bootstrap": "^4.3.2",
    "@types/bootstrap-3-typeahead": "^4.0.1",
    "@types/bootstrap-select": "^1.11.1",
    "@types/bootstrap-switch": "0.0.31",
    "@types/bootstrap-toggle": "^2.2.1",
    "@types/bootstrap-treeview": "^1.20.0",
    "@types/d3": "^5.7.2",
    "@types/datatables.net": "^1.10.19",
    "@types/datatables.net-select": "^1.2.6",
    "@types/jquery": "^1.10.35",
    "@types/jquerymobile": "^1.4.30",
    "@types/jqueryui": "^1.12.8",
    "@types/x-editable": "^1.5.29",
    "apidoc": "^0.25.0",
    "eslint": "^6.8.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-typescript": "^0.12.0",
    "prettier": "^1.19.1",
    "typescript": "^3.8.3",
    "typescript-eslint-parser": "^18.0.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "XXX XXX",
  "license": "ISC"
}

I also added the output for npm config and npm config ls -l below.

Output for npm config:

; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.8 node/v10.22.0 linux x64"

; builtin config undefined
globalconfig = "/etc/npmrc"
globalignorefile = "/etc/npmignore"
prefix = "/usr/local"

; node bin location = /usr/bin/node
; cwd = /home/myname
; HOME = /home/myname
; "npm config ls -l" to show all defaults.

Output of npm config ls -l:

; cli configs
long = true
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.8 node/v10.22.0 linux x64"

; builtin config undefined
globalconfig = "/etc/npmrc"
globalignorefile = "/etc/npmignore"
prefix = "/usr/local"

; default values
access = null
allow-same-version = false
also = null
always-auth = false
audit = true
audit-level = "low"
auth-type = "legacy"
before = null
bin-links = true
browser = null
ca = null
cache = "/home/myname/.npm"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cafile = undefined
cert = null
cidr = null
color = true
commit-hooks = true
depth = null
description = true
dev = false
dry-run = false
editor = "vi"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
format-package-lock = true
fund = true
git = "git"
git-tag-version = true
global = false
global-style = false
; globalconfig = "/usr/local/etc/npmrc" (overridden)
; globalignorefile = "/usr/local/etc/npmignore" (overridden)
group = 1000
ham-it-up = false
heading = "npm"
https-proxy = null
if-present = false
ignore-prepublish = false
ignore-scripts = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "/home/myname/.npm-init.js"
init-version = "1.0.0"
json = false
key = null
legacy-bundling = false
link = false
local-address = undefined
loglevel = "notice"
logs-max = 10
; long = false (overridden)
maxsockets = 50
message = "%s"
; metrics-registry = null (overridden)
node-options = null
node-version = "10.22.0"
noproxy = null
offline = false
onload-script = null
only = null
optional = true
otp = null
package-lock = true
package-lock-only = false
parseable = false
prefer-offline = false
prefer-online = false
; prefix = "/usr" (overridden)
preid = ""
production = false
progress = true
proxy = null
read-only = false
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = true
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
save-prod = false
scope = ""
script-shell = null
scripts-prepend-node-path = "warn-only"
searchexclude = null
searchlimit = 20
searchopts = ""
searchstaleness = 900
send-metrics = false
shell = "/bin/bash"
shrinkwrap = true
sign-git-commit = false
sign-git-tag = false
sso-poll-frequency = 500
sso-type = "oauth"
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
timing = false
tmp = "/tmp"
umask = 2
unicode = true
unsafe-perm = true
update-notifier = true
usage = false
user = 0
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} {ci}" (overridden)
userconfig = "/home/myname/.npmrc"
version = false
versions = false
viewer = "man"

I found .npmrc in /usr/lib/node_modules/npm and it is empty.

I found npmrc in /usr/local/lib/node_modules/npm and its content:

globalconfig=/etc/npmrc
globalignorefile=/etc/npmignore
prefix=/usr/local

Do you find anything odd from the contents above? I read npm-config and npmrc but can't find anything helpful.

Thanks.

like image 287
AEWRocks Avatar asked Mar 03 '23 01:03

AEWRocks


1 Answers

I had the same error, I deleted my package-lock.json file and my node_module folder and it worked.

like image 117
Homeslyce Avatar answered Mar 05 '23 15:03

Homeslyce