Title: require is not defined · Issue #7 · ModuleLoader/node-es-module-loader · GitHub
Open Graph Title: require is not defined · Issue #7 · ModuleLoader/node-es-module-loader
X Title: require is not defined · Issue #7 · ModuleLoader/node-es-module-loader
Description: Given this snippet: import bodyParser from 'koa-bodyparser'; import Koa from 'koa'; const chalk = require('chalk'); the result when trying to load this module is: const chalk = require('chalk'); ^ require is not defined I understand from...
Open Graph Description: Given this snippet: import bodyParser from 'koa-bodyparser'; import Koa from 'koa'; const chalk = require('chalk'); the result when trying to load this module is: const chalk = require('chalk'); ^ ...
X Description: Given this snippet: import bodyParser from 'koa-bodyparser'; import Koa from 'koa'; const chalk = require('chalk'); the result when trying to load this module is: const chal...
Opengraph URL: https://github.com/ModuleLoader/node-es-module-loader/issues/7
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"require is not defined","articleBody":"Given this snippet:\r\n\r\n```js\r\nimport bodyParser from 'koa-bodyparser';\r\nimport Koa from 'koa';\r\n\r\nconst chalk = require('chalk');\r\n```\r\n\r\nthe result when trying to load this module is:\r\n\r\n```\r\nconst chalk = require('chalk');\r\n ^\r\nrequire is not defined\r\n```\r\n\r\nI understand from this issue https://github.com/ModuleLoader/es-module-loader/issues/427 that the loader has made the assumption that the user only wants ES6 module support and not interoperability with require for CommonJS modules.\r\n\r\nWhile that is a perfectly good and reasonable argument for the es-module-loader module, the `node-esml` binary would imply by README description and name that there is a measure of interoperability with Node's current and default loader mechanisms. This would follow use of babel in node server-side code in which we're able to use `require` within ES6 modules.\r\n\r\nThe 'sync' nature of `require` can be duplicated using `async/await` patterns on the dynamic `import`, however that can only be used on node \u003e 7 with harmony flags, or node 7.6 - both of which are not yet options for a large chunk of developers due to restrictions in the workplace. \r\n\r\nI'd like to at the least point out this limitation and the perception that it _may_ be interpreted as a bug by folks not intimately familiar with loaders and/or es-module-loader. And I'd like to propose the interoperability with default node `require` support as a new feature.\r\n\r\nOr at the least, an updated README with a solution to provide support for `require`. If I'm missing something where require-like capabilities exist, such as the ability to load JSON files as objects, then please do consider adding those to the README, as I haven't found a suitable workaround as simplistic as requiring the file.","author":{"url":"https://github.com/shellscape","@type":"Person","name":"shellscape"},"datePublished":"2017-03-16T00:07:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/7/node-es-module-loader/issues/7"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d0b72f78-0ec3-f28f-dc30-0e8ac250f0c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEE4:3128EA:C1089D:1100FC2:696FBA91 |
| html-safe-nonce | 63c937cb22fcaed0db184e31a6cc70bed9ac751e72790b114a9c5fbdc52fb798 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUU0OjMxMjhFQTpDMTA4OUQ6MTEwMEZDMjo2OTZGQkE5MSIsInZpc2l0b3JfaWQiOiI3NzE3Njc0MzMyNzc4OTA0MjA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ab8ed58ba32ec10fce870f2bbe64049eaba21ae0fc75db77975e7c535bff6c93 |
| hovercard-subject-tag | issue:214562619 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/ModuleLoader/node-es-module-loader/7/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7550435caf4f1e4db10e4b81d804eb094aad1c763b86b9f29c5f76f1146c3b81/ModuleLoader/node-es-module-loader/issues/7 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7550435caf4f1e4db10e4b81d804eb094aad1c763b86b9f29c5f76f1146c3b81/ModuleLoader/node-es-module-loader/issues/7 |
| og:image:alt | Given this snippet: import bodyParser from 'koa-bodyparser'; import Koa from 'koa'; const chalk = require('chalk'); the result when trying to load this module is: const chalk = require('chalk'); ^ ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shellscape |
| hostname | github.com |
| expected-hostname | github.com |
| None | 40ce4030a7db32193be29054756ed7f7eceec3a82973f060300035bdff8cf777 |
| turbo-cache-control | no-preview |
| go-import | github.com/ModuleLoader/node-es-module-loader git https://github.com/ModuleLoader/node-es-module-loader.git |
| octolytics-dimension-user_id | 4904197 |
| octolytics-dimension-user_login | ModuleLoader |
| octolytics-dimension-repository_id | 65407421 |
| octolytics-dimension-repository_nwo | ModuleLoader/node-es-module-loader |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 65407421 |
| octolytics-dimension-repository_network_root_nwo | ModuleLoader/node-es-module-loader |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1cdcabe0d7ddc4be91a713d57280849e4c89f5cd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width