Is that just me ? the simplest example does not even work; breaking on the very first variable in ./build/index.js :
"use strict";
require = function (_require) { etc…
Or transforms/babelization/etc… (not shown in the example) are to be added first ?
Was on node6, upgrading to node8 let me run this example without issues (and the most basic one advertised on the 'getting started' page)
node8 is obviously required; so is a minimal .babelrc setup
Not a dropin webpack replacement at all :/, was too good to be true. Using the same package.json, I'm now getting hellish bugs when trying replace a webpack conf within an es6 app (...spreads
breaks, among other things), end up sad not being able to investigate further at the moment
We're relying on non-strict mode. Some tool (most likely Babel is adding in the "use strict"
.
We should probably update the prelude.js file to find the correct global to attach to.
@ljharb What's the best way to get global
(whether it be window/self/global/this
) today?
Just chiming in; I was getting a different error #31, but after that issue was fixed I'm now getting this error with node6.
In strict or sloppy mode, you can always use Function(‘return this’)()
in every engine except CSP-enabled browsers (however, for those, you can use window || self
.
I upgraded node v9.2.0 and solved it.
I was looking into the issue but I think even fixing the use strict problem we will have problems with babel transforming require = (function (modules, cache, entry) { ... })
to require = function (modules, cache, entry) { ... };
when the project is built.
So in node 7 and further, when the script is compiled by parcel and the browser loads, we have correctly require = (function (modules, cache, entry) { ... })([modules])
which is a iife. Because it uses the files under src/* which are not compiled it uses the original file. But in node 6 and before it generates require = function (modules, cache, entry) { ... };([modules])
. Which makes the page render nothing.
Not sure how to fix that. Maybe we could make babel ignore this specific file and just copy it to lib?
Also is it a bad idea to just not support node 6? I think people using parcel are mostly testing it or creating new stuff, in this case they can at least use a more up to date node version.
I just ended up upgrading to Node 8x series since it is on LTS
just upgrade the node version to v8.9.3,can fix this problem.
my node version is v6, this issue was be fixed after upgrade to v8
@xswei me,too! But do you know why?
i try it, since v7.0.0 to v7.9.0, it cannot run, but when I use v8.0.0, it done !, so, I guess parcel need Node version is greater than or equal to v8.0.0
@phobal But what results to the problem, I would like to konw the explaniation. It's all konwn that require
is supported at the node @v6.x.x
@wqcstrong right. node 6.x was supported, however, it run in node V8 environment, in browser cannot support require
@wqcstrong @phobal 老铁 parcel只支持8以上版本,具体原因知道吗?
Also bumped into this on Node 6.11. The first few lines of the generated file follow. Note the implicit global assignment in require = function(...)
, which is the reason the error is thrown in strict mode. Manually deleting the use strict
line, or using var require = function...
prevents the error from being thrown, but the generated file actually never calls the require
function.
"use strict";
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
require = function (_require) {
Edit: the reason require
doesn't get called is an extra semicolon after the definition of function(modules, cache, entry) { ... });(...)
. That semicolon means the function expression isn't immediately invoked.
@xswei 上面的大佬大概说了导致报错的原因了 @guilhermeasg :1、删除严格模式;2、var
声明变量
@guilhermeasg Hey buddy,I have tried to find the semicolon you said in the complied file, but I did not find it after reading what you said.
@wqcstrong thanks for following up. I uploaded the bundled file to a gist for direct examination. This file has been generated, as in the example in the main page, simply by running parcel index.html
on the provided file.
Note that line 11 is an implicit global definition, which is forbidden in strict mode (L1), hence the error. Furthermore, take a look at L80:
});({7:[function(require,module,exports) {
The expression after the semicolon is supposed to be the argument to the previously defined function (making it an IIFE), but the semicolon breaks it into an object declaration with no side effects.
Looking forward to this fix pending (#253).
To the project maintainers:
Having recently heard about Parcel and it's zero configuration feature, I was eager to try it out on a new project, but quickly found that the "Getting Started" example just fails, which needless to say is not a good reflection upon this library. My suggestion (until this issue is fixed) would be for you to list the current limitation (requires nodeJS v > 6) on your README file and website.
Appreciate the work that has gone into this library and for the introduction of a zero config bundler. I will revisit this again in the future...
what wrong to write
var require = function (_require) {
instead of just
require = function (_require) {
?
It make it global just fine
@perymimon see my comment for the reason
Just as an update:
I'm getting this issue with parcel bundler version 1.4.1 & node version v9.4.0.
Both fresh installs today.
@mike-rotate Can you try it again using the new Parcel version?
Still getting the same issue.
Node version : 9.5.0
Parcel version : 1.5.1
Just have a button in my html page which on clicking calls the clickHandler function in the js file. Get an error saying 'ReferenceError: clickHandler is not defined'. I could find the function in the built js file under dist.
Note: have configured to use babel. But still.. 😞
Node 6 support was just merged in #789. Should be released in 1.6.0 this week!
Most helpful comment
I upgraded node v9.2.0 and solved it.