GithubHelp home page GithubHelp logo

Comments (7)

giltayar avatar giltayar commented on May 26, 2024 2

I have to admit that this seems counter-intuitive to me. Maybe logical, but counter-intuitive:

If I do

import './foo?x=4'

Then I import the file ./foo.mjs, and the x=4 is part of the cache key, so is used as a "cache buster".

But if I do

import 'foo?x=4'

Then we're importing the package in the folder/file node_modules/foo?x=4? I would expect to load node_modules/foo with a cache-busting x=4.

While I understand the logic—bare imports are not URLs, and should not be treated as such—I believe most people wouldn't understand this and would be surprised by this behavior, especially if

import 'foo/bar?x=4'

is treated (somewhat) as a URL and the x=4 suddenly becomes a cache-buster again.

In the interest of the principle of least-surprise, I hope it doesn't land this way.

from modules.

jdalton avatar jdalton commented on May 26, 2024 1

Wouldn't this also impact how folks were planning to handle reloading modules
(e.g. the cache buster hash trick from the browser)?

from modules.

jdalton avatar jdalton commented on May 26, 2024

\cc @iarna for npm since it's package name related.

from modules.

guybedford avatar guybedford commented on May 26, 2024

In the current implementation the above falls into the ResolveModule path at https://github.com/nodejs/node/blob/master/src/module_wrap.cc#L594. Which then concatenates the specifier into the node_modules lookup. Once found, the path is taken to be the part after the package name length.

So the above example would check the directory node_modules/foo?a directly on the filesystem.

So we're actually already pretty locked down and in agreement with the package map approach here.

from modules.

bmeck avatar bmeck commented on May 26, 2024

@jdalton to an extent?

@guybedford that is a good catch and would have been considered a bug if I saw it before this issue. Since it was not my intention when writing that to have that specific behavior it seems we should still talk about it though.

from modules.

bmeck avatar bmeck commented on May 26, 2024

@giltayar you can post the issue I created in package name maps, but I did not see a way to argue about it if prohibiting the characters is seen as a bad idea. Any way it goes, we should match package name maps.

from modules.

bmeck avatar bmeck commented on May 26, 2024

Conclusion should stand and we aren't discussing this anymore.

from modules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.