garycourt/uri-js

Please publish pre-compiled version of uri-js

Closed this issue ยท 10 comments

From https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify:

<<To resolve this:
Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled.>>

I got this error message when trying to build my app using react-scripts:
.............................
Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file:

./node_modules/uri-js/dist/esnext/uri.js:42

Read more here: http://bit.ly/2tRViJ9

error Command failed with exit code 1.

.............................

Could you please publish precompiled version as stated above?
I am receiving the same error when trying to run npm build.

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file:

./node_modules/uri-js/dist/esnext/uri.js:42

Read more here: http://bit.ly/2tRViJ9

The issue is the module key in package.json.

I've adjusted create-react-app build script to remove that line and the build went successfully:

"build": "npm run build-fix && react-scripts build",
"build-fix": "sed -i '/index.js/d' node_modules/uri-js/package.json",

@gabdara I do not know npm packaging well enough, but would simply removing that line be the solution? Could that be a simple PR, so that the maintainer would just merge it?

First off, URI is published with 2 pre-compiled versions. One in ES5, and one in ES6+ (ESNext). Both can be found in the ./dist folder. The error you are getting is because your minifier failed to parse the esnext version, likely due to missing syntax support. This is is not a problem with URI. I recommend updating to the latest versions of your minifier, and seeing if it has support for the latest EcmaScript features.

## Solved
@mislavKucanda , I was getting same issue when I was building a React Application.
I resolved this while building react project in this way:
go to /node_modules/uri-js/dist/
There you will find two folders:
1-es5
2-esnext

Now rename esnext to some other name or delete this folder and start building your react project.

NOTE: Use this trick only while building the application .
@danrot : Your answer was inspiring ๐Ÿ‘

@garycourt You are correct !
Hope it helps if you have not resolved yet !

@garycourt do you understand the problem people have with ajv?

To the extend that has been explained here. The problem is with the minifier and not with URI.js.

Or you can add this to your webpack.config.js

alias: {
  ...
  'uri-js': path.resolve('.', 'node_modules', 'uri-js', 'dist', 'es5', 'uri.all.js'),
  ...
}
Fer0x commented

@garycourt No, the problem is with URI.js package.json's field module.
The field module is for ES6 Modules bundles (spec).
It means, that js code should use import/export rather of require(). But also in https://github.com/garycourt/uri-js/blob/master/dist/esnext/uri.js there is some ES6-compatible code like operators const and let which are not parts of ES5.
So you can't just put ES6 version in module field, because it's not expected by bundlers like webpack. It similar to putting ES6 version to main package.json's field - which is not good practice.
So, please, provide a ES5-compatible version of URI.js with ES6 modules syntax in 'module' field.

@Fer0x Yes, between my last comment and now, I've come to understand the scope of the problem better. Version uri-js@^4.2.2 should fix this issue.