Opened 16 months ago

Last modified 12 months ago

#34322 closed Bug

ManifestStaticFilesStorage crashes on commented JavaScript import statements — at Version 3

Reported by: Adam Johnson Owned by: nobody
Component: contrib.staticfiles Version: 4.2
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adam Johnson)

#32319 added module support to ManifestStaticFilesStorage. It can crash with imports in comments, which are used for Typescript (docs) but don't necessarily resolve when code is bundled.

Example from htmx:

//** @type {import("./htmx").HtmxApi} */

Leads to:

whitenoise.storage.MissingFileError: The file 'example/dist/htmx' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x16ff630a0>.

The JS file 'example/dist/app.js' references a file which could not be found:
  example/dist/htmx

Please check the URL references in this JS file, particularly any
relative paths which might be pointing to the wrong location.

The regex should be adjusted to only select imports that are alone on a line, with whitespace.

This may be a challenge as comments can be multi-line like:

        /**
         * @param {HTMLElement} elt
         * @returns {import("./htmx").HtmxTriggerSpecification[]}
         */

Change History (3)

comment:1 by Carlton Gibson, 16 months ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Grrr. OK. Sigh. Thanks for the report Adam. (I didn't run it, but I'm going to trust you)

(Mariusz was right to be sceptical that this was going to be OK. . :)

Let's look at a fix here but:

I think we need to be prepared to say where we're not going to try more complex solutions.
(https://code.djangoproject.com/ticket/32319#comment:21)

comment:2 by Adam Johnson, 16 months ago

Summary: ManifestStaticFilesStorage crashesManifestStaticFilesStorage crashes on commented JavaScript import statements

comment:3 by Adam Johnson, 15 months ago

Description: modified (diff)

Added more detail to description about possible failures

Note: See TracTickets for help on using tickets.
Back to Top