npm publish unexpected token u in JSON at position 0 - npm

I got the below error on call npm publish. I was trying publish an existing package on private feed:
npm ERR! Unexpected token u in JSON at position 0
My package.json:
{
"name": "XXXXXXXXXXXX",
"version": "0.0.6",
"description": "XXXXXXXXXXXX",
"types": "./types/index.d.ts",
"repository": {
"type": "git",
"url": "XXXXXXXXXXXX"
},
"engines": {
"cordovaDependencies": {
"0.2.3": {
"cordova": ">=3.1.0"
},
"4.0.0": {
"cordova": ">100"
}
}
}
}

To me, its happened because of the "engines" group in package.json. I removed it, and npm publish works.

Related

Can someone help me resolve this problem? Fatal error: Unable to find local grunt

I am learning hybris and I started using smartedit. The problem is that when I run ant clean all or ant updatesystem I get this error.
Running grunt default
grunt-cli: The grunt command line interface (v1.3.2)
Fatal error: Unable to find local grunt.
If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:
https://gruntjs.com/getting-started
What have I done till now:
I have grunt-cli installed globally, and grunt installed locally. Also, I run npm install.
Here is my packege.json file:
{
"name": "name",
"version": "1.0.0",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^1.4.1",
"grunt-contrib-jshint": "^3.0.0",
"grunt-contrib-watch": "^1.1.0"
},
"dependencies": {},
"description": "desc"
}
Here is my Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['jshint']);
};
I tried a bunch of ways to resolve this problem but nothing seemed to work. Can someone help me out?

db-migrate with #babel/register and ES6 modules - "SyntaxError: Unexpected token export" error

Really hoping someone can help me with this as it's driving me crazy.
Node v12.4.0
package.json: -
{
"name": "#mypackage/db-migrate",
"private": true,
"version": "1.0.0",
"main": "index.js",
"license": "ISC",
"workspaces": {
"packages": [
"common/models"
]
},
"dependencies": {
"#babel/core": "^7.6.0",
"#babel/preset-env": "^7.6.0",
"#babel/register": "^7.6.0",
"#mypackage/models": "1.0.0",
"db-migrate-mysql": "^1.1.10",
"db-migrate-plugin-babel": "^2.0.1",
"npm-upgrade": "^2.0.2"
}
}
.babelrc: -
{
"presets": [
"#babel/preset-env"
]
}
Directory structure: -
common->models - this contains the source lib for #mypackage/models
migrations - contains all the migration files
Yarn installs all the dependencies without issue.
So when I run a migration command ("db-migrate down -c 1", for example), I get the following: -
export { CONSTANT_ONE, CONSTANT_TWO, CONSTANT_THREE };
^^^^^^
SyntaxError: Unexpected token export
This is happening when I am trying to export/import from one of the #mypackage/models files.
var CONSTANT_ONE = "foo_one";
var CONSTANT_TWO = "foo_two";
var CONSTANT_THREE = "foo_three";
export { CONSTANT_ONE, CONSTANT_TWO, CONSTANT_THREE };
Is this a root directory issue? I am complete baffled and utterly frustrated. Any help VERY welcome.
Solved by changing .babelrc to babel.config.js.

Npm Publish Issue - Artifactory

I am publishing an npm library to an npm repo on artifactory. The library is built using angular and the dist folder and package.json looks correct. When publishing, the request it's self is published but not the actual artifact.
All i see on artifactory is a single file and not a folder containing my package
Running
npm publish
Package.json
{
"name": "#abce/embedded-auth",
"version": "1.0.0-dev.0",
"main": "bundles/abce-auth.umd.js",
"module": "fesm5/abce-auth.js",
"es2015": "fesm2015/abce-auth.js",
"esm5": "esm5/abce-auth.js",
"esm2015": "esm2015/abce-auth.js",
"fesm5": "fesm5/abce.js",
"fesm2015": "fesm2015/abce-auth.js",
"typings": "abce-auth.d.ts",
"metadata": "abce-auth.metadata.json",
"sideEffects": false,
"dependencies": {
"tslib": "^1.9.0"
}
}
What actually gets published to artifactory in a single file.
{
"_id": "#abce/embedded-auth",
"name": "#abce/embedded-auth",
"dist-tags": {
"latest": "1.0.0-dev.1"
},
"versions": {
"1.0.0-dev.1": {
"name": "#abce/embedded-auth",
"version": "1.0.0-dev.1",
"main": "bundles/abce-auth.umd.js",
"module": "fesm5/abce-auth.js",
"es2015": "fesm2015/abce-auth.js",
"esm5": "esm5/abce-auth.js",
"esm2015": "esm2015/abce-auth.js",
"fesm5": "fesm5/abce-auth.js",
"fesm2015": "fesm2015/abce-auth.js",
"typings": "abce-auth.d.ts",
"metadata": "abce-auth.metadata.json",
"sideEffects": false,
"dependencies": {
"tslib": "^1.9.0"
},
"readme": "ERROR: No README data found!",
"_id": "#abce/embedded-auth#1.0.0-dev.1",
"_npmVersion": "6.4.1",
"_nodeVersion": "10.15.3",
"_npmUser": {
"name": "deployment",
"email": "bob#bob.ie"
},
"maintainers": [
{
"name": "deployment",
"email": "bob#bob.ie"
}
],
"dist": {
"integrity": "sha512-rpTN1sMpwnMwehzWUqbV+zElzaOlF5ekQRCQMncy6c+i4TAp5jbBobvzrhgl0ORqHgJn3Eo+EcrRgYLSjV7MdQ==",
"shasum": "71f654dd5fddb20a9d5063171d5293424a4271c7",
"tarball": "http://abce.jfrog.io/abce/internal-npm-dev/#abce/embedded-auth/-/#abce/embedded-auth-1.0.0-dev.1.tgz"
}
}
},
"readme": "ERROR: No README data found!",
"maintainers": [
{
"name": "deployment",
"email": "bob#bob.ie"
}
],
"_attachments": {
"#abce/embedded-auth-1.0.0-dev.1.tgz": {
"content_type": "application/octet-stream",
"data": "correctly populated tarball base64 data here. I checked it and it is correct",
"length": 12092
}
}
}
Expect:
I would expect the package to be parsed from the request and the package published correctly
Actual:
The put request data from the npm publish command is published as a file
npm version: 6.9.0
node version: v12.3.1(has also been run with 10.15.3)
Any ideas?
Please check the registry URL that you are using from npm, if it doesn't include /api/npm - it is invalid.
Wrong URL: https://domain/artifactory/some-directory/.
Valid URL: https://domain/artifactory/api/npm/some-directory/.

Unable to resolve 'react-navigation'

Am trying out react-native and get below error, when I install and try to use react-navigation (import {StackNavigator} from 'react-navigation';).
Error
I use the following command to install "react-navigation" : npm install --save react-navigation
On running above command I get 'react-navigation' folder under node_modules folder, with just a single file (package.json). Below is the content of the file:
{
"_args": [
[
{
"raw": "react-navigation#0.0.0",
"scope": null,
"escapedName": "react-navigation",
"name": "react-navigation",
"rawSpec": "0.0.0",
"spec": "0.0.0",
"type": "version"
},
"/Users/rakesh-1812/Documents/REACT_JS/SimpleApp"
]
],
"_from": "react-navigation#0.0.0",
"_id": "react-navigation#0.0.0",
"_inCache": true,
"_location": "/react-navigation",
"_nodeVersion": "4.2.1",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/react-navigation-0.0.0.tgz_1459892254509_0.1584461957681924"
},
"_npmUser": {
"name": "ericvicenti",
"email": "ericvicenti#gmail.com"
},
"_npmVersion": "2.14.7",
"_phantomChildren": {},
"_requested": {
"raw": "react-navigation#0.0.0",
"scope": null,
"escapedName": "react-navigation",
"name": "react-navigation",
"rawSpec": "0.0.0",
"spec": "0.0.0",
"type": "version"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-0.0.0.tgz",
"_shasum": "1e0f865235cdb4d4aa8086484fd3690ff73df553",
"_shrinkwrap": null,
"_spec": "react-navigation#0.0.0",
"_where": "/Users/rakesh-1812/Documents/REACT_JS/SimpleApp",
"dependencies": {},
"description": "Coming Soon",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "1e0f865235cdb4d4aa8086484fd3690ff73df553",
"tarball": "https://registry.npmjs.org/react-navigation/-/react-navigation-0.0.0.tgz"
},
"maintainers": [
{
"name": "ericvicenti",
"email": "ericvicenti#gmail.com"
}
],
"name": "react-navigation",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"scripts": {},
"version": "0.0.0"
}
Can someone please help me resolve the issue. Thanks in advance.
React navigation is still in beta. It works for me when I use the command:
npm install --save react-navigation#1.0.0-beta.7
This is the latest release. https://github.com/react-community/react-navigation/releases
You must stop your node server and start it again.
Do it:
sudo lsof -n -i4TCP:8081 | grep LISTEN
It will listen of the services that are running on port 8081. By default, react native server runs on it. Then, execute the command below to kill the server process.
kill -9 <cma process id>
Finally, run your project again with
react-native run-ios
on the project folder
I was unable to install react-native, tried everything from the internet. Using Yarn instead of npm resolved the problem.
Try installing react-navigation stack, npm i react-navigation-stack. Then import {createStackNavigator} from 'react-navigation-stack'
Stop the server and run your project again.

npm run script causes Windows Script Host error

I a trying to use npm to minify javascript.
This is my package.json:
{
"name": "name1",
"version": "1.0.0",
"description": "",
"scripts": {
"minifyjs": "minifyJs",
"minifycss": "minifyCss",
"minifyhtml": "minifyHtml"
},
"author": "",
"license": "ISC",
"devDependencies": {
"clean-css": "^3.4.19",
"html-minifier": "^3.0.2",
"uglify-js": "^2.7.0"
}
}
and my minifyJs script is :
var uglifyJS = require('uglify-js');
var fs = require('fs');
var result = uglifyJS.minify(['src/main1.js', 'src/main2.js'], {
compress: {
drop_console: true,
unused: true
}
});
fs.writeFileSync('dist/minifyJs.js', result.code);
When I call npm run minifyjs I get the following error:
What am I doing wrong - btw this was working on another machine.....
Can anyone help?
The entries under scripts are commands that are run by NPM. They are not simply paths to JavaScript files.
You need to tell NPM to run your JavaScript tasks using node:
...
"scripts": {
"minifyjs": "node minifyJs",
"minifycss": "node minifyCss",
"minifyhtml": "node minifyHtml"
},
...