question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile JS without requires

See original GitHub issue

I’m using 2.0.0-alpha.3.2 and I wonder how can I build JS file without require() calls in it?

If I call parcel build index.html then I get it right. But due to my current project structure I need to have parcel build app.js (in order to have constant minified JS file name). But in this case, it compiles unusable for browser execution (has require() calls inside).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ricardobeatcommented, Jan 6, 2020

Having the same issue here. The moment I add targets to package.json it starts compiling to commonjs require() calls even for the browsr target. I have none of main, default, or other extra fields in package.json.

.babelrc:

{
  "presets": [
    ["@babel/preset-react"],
    ["@babel/preset-typescript"]
  ],
  "plugins": [
    "@babel/plugin-transform-runtime",
    "@babel/proposal-class-properties",
    "@babel/proposal-object-rest-spread",
    "inline-react-svg"
  ]
}
"targets": {
    "server": {
      "includeNodeModules": false,
      "outputFormat": "commonjs",
      "engines": {
        "node": ">=10.x"
      }
    },
    "browser": {
      "engines": {
        "browsers": [
          "> 1%",
          "not dead"
        ]
      }
    }
  }

I’m also seeing a bunch of @parcel/packager-js: Cannot read property 'constantViolations' and Error: Got unexpected undefined depending on how I setup these, quite hard to pinpoint what’s going on.

0reactions
maximalcommented, May 12, 2020

This solution is useless if you guys want to have external modules (like external jQuery or Bootstrap) and browser builds simultaneously. As described in https://github.com/parcel-bundler/parcel/pull/4072#issuecomment-627428171

Classic Parcel of version 1 solves it with parcel-plugin-externals plugin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to compile require statements? - javascript - Stack Overflow
Transpiling your code is not enough to make it work in a browser. You will need a build system like webpack to bundle...
Read more >
Should You Compile Your JavaScript Code? - Bits and Pieces
That is not the same as compiling JavaScript. ... But then again, it might not be required for you to write ES6-compatible code...
Read more >
JavaScript needs the compile step (on install) - Gleb Bahmutov
We all pretend that JavaScript is unique because it does not require a build or compile step on the client. Yet, this is...
Read more >
Requiring modules in Node.js: Everything you need to know
If you want to only resolve the module and not execute it, you can use the require.resolve function. This behaves exactly the same...
Read more >
RequireJS in Node
Yes! The Node adapter for RequireJS, called r.js, will use Node's implementation of require and Node's search paths if the module is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found