sindresorhus / p-defer Goto Github PK
View Code? Open in Web Editor NEWCreate a deferred promise
License: MIT License
Create a deferred promise
License: MIT License
When I am importing p-defer
in create-react-app@1
(with [email protected]
), then run npm run build
. I got the following error "Failed to minify the code from this file: p-defer/index.js:2".
The primary reason is because index.js
is not ES5-compliant (use of arrow functions). If I modify two "arrow functions" into traditional one, it will pass create-react-app
build.
'use strict';
module.exports = function () {
const ret = {};
ret.promise = new Promise(function (resolve, reject) {
ret.resolve = resolve;
ret.reject = reject;
});
return ret;
};
On the other side, create-react-app@2
changed the behavior and it will start building ES6+ files under /node_modules/
. So it do not repro in create-react-app@2
. But unfortunately, create-react-app@2
was just released in October 1st 2018. I bet there are lots of projects still running under create-react-app@1
and will keep it that way for another 1-2 years.
I am unsure if p-defer
should be ES5 or ES6 compliant by default. NPM don't have a strict guideline. So I will leave it open for the contributors to decide how to resolve this issue.
Error from npm run build
of react-scripts
:
> react-scripts build
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/p-defer/index.js:2
Read more here: http://bit.ly/2tRViJ9
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I get the following error when using [email protected]
. The error is explicit, and offers 2 possible solutions.
Error: Must use import to load ES Module: /home/yosbel/Documents/experiments/procplay/node_modules/p-defer/index.js
require() of ES modules is not supported.
require() of /home/yosbel/Documents/experiments/procplay/node_modules/p-defer/index.js from /home/yosbel/Documents/experiments/procplay/.next/server/pages/_app.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/yosbel/Documents/experiments/procplay/node_modules/p-defer/package.json.
It looks like this module can be deprecated sometime in the future, thanks to this Stage-3 proposal: https://github.com/tc39/proposal-promise-with-resolvers
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.