jest-schematic icon indicating copy to clipboard operation
jest-schematic copied to clipboard

Invalid JSON character: "\n" at 59:34.

Open eloiqs opened this issue 6 years ago • 13 comments

Describe the bug I followed the read me and when running the add schematics it printed Invalid JSON character: "\n" at 59:34.

To Reproduce Steps to reproduce the behavior:

  1. install the package globally
  2. run the add schematic in an angular project

Expected behavior The schematic runs

Desktop (please complete the following information):

  • OS: windows
  • Node version: 8.12
  • NPM or Yarn version 6.4.1
  • App type Angular CLI
  • Angular version 7.0.2

eloiqs avatar Nov 14 '18 20:11 eloiqs

Thank you for reporting. This schematic changes two json files, package.json and tsconfig.spec.json. Are you able to determine which file the error is coming from based on the line number (59)? Changes to tsconfig.spec.json are new so thats the likely culprit.

schuchard avatar Nov 15 '18 06:11 schuchard

This is my tsconfig.spec.json

{
	"extends": "./tsconfig.json",
	"compilerOptions": {
		"noEmit": false,
		"outDir": "../out-tsc/spec",
		"module": "commonjs",
		"types": ["jasmine", "node"]
	},
	"files": ["test.ts", "polyfills.ts"],
	"include": ["**/*.spec.ts", "**/*.d.ts", "**/*.mock.ts"]
}

The tsconfig which it extends

{
	"compileOnSave": false,
	"compilerOptions": {
		"baseUrl": "./",
		"noEmit": true,
		"sourceMap": true,
		"declaration": false,
		"moduleResolution": "node",
		"emitDecoratorMetadata": true,
		"experimentalDecorators": true,
		"target": "es5",
		"typeRoots": ["../node_modules/@types"],
		"lib": ["es2017", "dom"],
		"noImplicitAny": true,
		"noImplicitReturns": true,
		"noUnusedLocals": true,
		"noUnusedParameters": true
	}
}

So, even combined, there is no line 59 😕

eloiqs avatar Nov 15 '18 21:11 eloiqs

Was there every any solution to this? I'm getting a similar issue Invalid JSON character: "-" at 76:5. no other output

acharlop avatar Jul 18 '19 19:07 acharlop

I think we ended up using https://github.com/just-jeb/angular-builders/tree/master/packages/jest instead :/

eloiqs avatar Jul 30 '19 13:07 eloiqs

in my case it turned out to be a packge.json npm script that contained the following string \\nsomefolder , the characters '\n' verbatim were in the file causing the error. adding the file name that is the problem to the error string would have helped.

Also not having a "test" script in the packge.json seems to cause a similar error

menaheme avatar Mar 17 '20 12:03 menaheme

This might be resolved in the latest PR https://github.com/briebug/jest-schematic/pull/37/files#diff-99dba52ba3c99a2cb3d95d1ada2821f8R278 where we looses the "strictness" of the JSON parsing. Can anyone test the current schematic to see if it's fixed?

schuchard avatar Sep 02 '20 12:09 schuchard

This should be fixed in the latest 3.0.0 release with https://github.com/briebug/jest-schematic/pull/37/files#diff-99dba52ba3c99a2cb3d95d1ada2821f8R278. Please reopen if not.

schuchard avatar Sep 25 '20 12:09 schuchard

I just used the latest version of this project and I had the same issue:

ng add @briebug/jest-schematic
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Invalid JSON character: "\n" at 155:35.

It seems to happen in my package.json but at said line and curser position there is only a whitespace.

markusmo avatar Jan 25 '21 15:01 markusmo

For those still having problems, what operation systems are you using?

schuchard avatar Feb 04 '21 18:02 schuchard

For those still having problems, what operation systems are you using?

I'm so sorry. I realized that I am in the @jest-schematic repo. My apologies. I'm using cypress-schematic. I'll delete my comment and post in the correct repo. My apologies @schuchard

chrisleyva avatar Feb 04 '21 18:02 chrisleyva

For those still having problems, what operation systems are you using?

I am using Windows 10 image

But my issues I think where, that \t and \n made some issues. I guess it has to do something with my line endings. which are set to CRLF and will be only be changed, when I commit to LF.

markusmo avatar Feb 08 '21 09:02 markusmo

ng add @briebug/jest-schematic

ℹ Using package manager: npm
✔ Found compatible package version: @briebug/[email protected].
✔ Package information loaded.

The package @briebug/[email protected] will be installed and executed.
Would you like to proceed? Yes
✔ Package successfully installed.
Invalid JSON character: "\"" at 81:11.

Angular 13 MacOS 14.1

btd1337 avatar Nov 01 '23 22:11 btd1337

ng add @briebug/jest-schematic i Using package manager: npm √ Found compatible package version: @briebug/[email protected]. √ Package information loaded.

The package @briebug/[email protected] will be installed and executed. Would you like to proceed? Yes √ Packages successfully installed. Invalid JSON character: "\t" at 53:24.

Angular 16 Windows 10

a-boertien avatar Nov 02 '23 16:11 a-boertien