I am confused about how importmaps is supposed to replace yarn. Particularly I’m having difficulty with the underscore npm package. I did the following as the docs have said to use the same package name as on npm but with the pin command:
./bin/importmap pin underscore
It correctly added underscore.js
to /vendor/javascript
and added the pin to my importmap config.
pin "underscore" # @1.13.7
But when I try to import the functionality I need like this:
import debounce from 'underscore';
I just get a ton of errors about missing files:
Started GET "/assets/index-default.js" for ::1 at 2024-12-20 13:19:59 -0500
13:19:59 web.1 | Started GET "/_/CzPGziMj.js" for ::1 at 2024-12-20 13:19:59 -0500
13:19:59 web.1 | Started GET "/assets/_setup.js" for ::1 at 2024-12-20 13:19:59 -0500
13:19:59 web.1 | Started GET "/assets/restArguments.js" for ::1 at 2024-12-20 13:19:59 -0500
13:19:59 web.1 | Started GET "/assets/isObject.js" for ::1 at 2024-12-20 13:19:59 -0500
13:20:00 web.1 |
13:20:00 web.1 | ActionController::RoutingError (No route matches [GET] "/_/CzPGziMj.js"):
13:20:00 web.1 |
13:20:01 web.1 | Started GET "/assets/isUndefined.js" for ::1 at 2024-12-20 13:20:01 -0500
13:20:01 web.1 | Started GET "/assets/isBoolean.js" for ::1 at 2024-12-20 13:20:01 -0500
13:20:01 web.1 | Started GET "/assets/isElement.js" for ::1 at 2024-12-20 13:20:01 -0500
13:20:01 web.1 | Started GET "/assets/isString.js" for ::1 at 2024-12-20 13:20:01 -0500
13:20:06 web.1 | Started GET "/assets/isNumber.js" for ::1 at 2024-12-20 13:20:06 -0500
13:20:06 web.1 | Started GET "/assets/isDate.js" for ::1 at 2024-12-20 13:20:06 -0500
13:20:06 web.1 | Started GET "/assets/isRegExp.js" for ::1 at 2024-12-20 13:20:06 -0500
13:20:06 web.1 | Started GET "/assets/isError.js" for ::1 at 2024-12-20 13:20:06 -0500
13:20:07 web.1 | Started GET "/assets/isNull.js" for ::1 at 2024-12-20 13:20:07 -0500
13:20:07 web.1 | Started GET "/assets/isArrayBuffer.js" for ::1 at 2024-12-20 13:20:07 -0500
13:20:07 web.1 | Started GET "/assets/isDataView.js" for ::1 at 2024-12-20 13:20:07 -0500
13:20:07 web.1 | Started GET "/assets/isArray.js" for ::1 at 2024-12-20 13:20:07 -0500
13:20:07 web.1 | Started GET "/assets/isFunction.js" for ::1 at 2024-12-20 13:20:07 -0500
13:20:08 web.1 | Started GET "/assets/isArguments.js" for ::1 at 2024-12-20 13:20:08 -0500
13:20:08 web.1 | Started GET "/assets/isFinite.js" for ::1 at 2024-12-20 13:20:08 -0500
13:20:08 web.1 | Started GET "/assets/isNaN.js" for ::1 at 2024-12-20 13:20:08 -0500
13:20:08 web.1 | Started GET "/assets/isTypedArray.js" for ::1 at 2024-12-20 13:20:08 -0500
13:20:08 web.1 | Started GET "/assets/isEmpty.js" for ::1 at 2024-12-20 13:20:08 -0500
...
And it makes sense looking at the actual downloaded file, it just exports the default functions from a bunch of files with relative paths that were not downloaded with underscore.js:
// underscore@1.13.7 downloaded from https://ga.jspm.io/npm:underscore@1.13.7/modules/index-all.js
export{default}from"./index-default.js";import"../_/CzPGziMj.js";export{VERSION}from"./_setup.js";export{default as restArguments}from"./restArguments.js";export{default as isObject}from"./isObject.js";export{default as isNull}from"./isNull.js";export{default as isUndefined}from"./isUndefined.js";export{default as isBoolean}from"./isBoolean.js";...
I used to use yarn, and looking at what was downloaded in node_modules when this was working, I see underscore.js along with its minified versions and various others in the top level of an underscore folder, with all the missing files in a subfolder called modules
.
How is importmaps-rails supposed to work managing dependencies like this? Is there a way I can tell it to download an entire package the way you would with yarn or npm? Or does it rely on serving from a cdn? I’d prefer not to rely on cdns, but I’d also like to not check in every single dependency to my repository.
I thought that importmaps could handle dependency management and versioning the same way we used yarn. I see that ./bin/importmap pin X
replaces yarn add X
it does not actually download the full package it seems. And I can’t find an equivalent to yarn install
for someone who is checking out the repository. This question is from someone with exactly the same requirements as me but I couldn’t get the --download
flag to work with underscore.
Thanks for any help!