Fix build by converting bookmarkletify.js to an ES module#7
Open
tom93 wants to merge 1 commit into
Open
Conversation
The package 'get-stdin' switched to an ES module in version 9.0.0 [1],
which broke the build (full error message below).
The error could be fixed by switching to a dynamic import(), namely
`import('get-stdin').then(...)`, but that's awkward; so instead this
commit converts bookmarkletify.js to an ES module (by changing the
file extension to .mjs), which allows using the nicer import statement
syntax: `import getStdin from 'get-stdin';`.
There is an additional problem: import specifiers don't support the
NODE_PATH environment variable[2] and only search local 'node_modules'
directories, so the 'get-stdin' module is not found.
This commit fixes the module search problem by installing the
'get-stdin' package locally instead of globally. (The other packages
are still installed globally, so that their executables will be
available in the default $PATH.)
The final complication is the location of the 'node_modules'
directory. The build command bind-mounts the repository into the
container on /kill-sticky. Creating a 'node_modules' directory inside
/kill-sticky at build time wouldn't work, because the bind mount would
hide it. And creating it at runtime is ugly, because it pollutes the
directory outside the container.
Instead, this commit moves /kill-sticky to /build/kill-sticky, and
then creates the 'node_modules' directory in /build (outside the
'kill-sticky' directory so it won't pollute the repository, but still
in the module search path).
---
Here is the error message with get-stdin 9.0.0 prior to this commit:
```
/kill-sticky/src/bookmarkletify.js:1
const getStdin = require('get-stdin');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/get-stdin/index.js from /kill-sticky/src/bookmarkletify.js not supported.
Instead change the require of index.js in /kill-sticky/src/bookmarkletify.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/kill-sticky/src/bookmarkletify.js:1:18) {
code: 'ERR_REQUIRE_ESM'
}
```
[1]: sindresorhus/get-stdin@8f70f58
[2]: https://nodejs.org/docs/latest-v19.x/api/esm.html#no-node_path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The package 'get-stdin' switched to an ES module in version 9.0.0 [1], which broke the build (full error message below).
The error could be fixed by switching to a dynamic import(), namely
import('get-stdin').then(...), but that's awkward; so instead this commit converts bookmarkletify.js to an ES module (by changing the file extension to .mjs), which allows using the nicer import statement syntax:import getStdin from 'get-stdin';.There is an additional problem: import specifiers don't support the NODE_PATH environment variable[2] and only search local 'node_modules' directories, so the 'get-stdin' module is not found.
This commit fixes the module search problem by installing the 'get-stdin' package locally instead of globally. (The other packages are still installed globally, so that their executables will be available in the default $PATH.)
The final complication is the location of the 'node_modules' directory. The build command bind-mounts the repository into the container on /kill-sticky. Creating a 'node_modules' directory inside /kill-sticky at build time wouldn't work, because the bind mount would hide it. And creating it at runtime is ugly, because it pollutes the directory outside the container.
Instead, this commit moves /kill-sticky to /build/kill-sticky, and then creates the 'node_modules' directory in /build (outside the 'kill-sticky' directory so it won't pollute the repository, but still in the module search path).
Here is the error message with get-stdin 9.0.0 prior to this commit:
[1]: sindresorhus/get-stdin@8f70f58
[2]: https://nodejs.org/docs/latest-v19.x/api/esm.html#no-node_path