thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
934 stars 87 forks source link

IDE cannot resolve imported local file #241

Open ultimate-tester opened 4 years ago

ultimate-tester commented 4 years ago

Hi,

I'm shimming a file called "Foo.js". This file is local and it's path relative to my entry file is "../FolderB/Foo.js". With the following configuration I am able to shim it:

"browserify-shim": {
        "Foo": "global:Foo"
    }

And then I imported it with

import Foo from 'Foo'

This works fine with Browserify, but the IDE gets confused and tells me "Module is not installed". Is there any way to specify the absolute path to the file in browserify-shim config and make it recognize the relative import from my entry file so both Browserify-shim and the IDE are happy?

bendrucker commented 4 years ago

I don't think so. Is there a reason you're not using a proper relative path, i.e. ./foo? This is important to distinguish between registry/builtin packages and local modules.

ultimate-tester commented 4 years ago

I don't think so. Is there a reason you're not using a proper relative path, i.e. ./foo? This is important to distinguish between registry/builtin packages and local modules.

Yeah, well the reason behind that is that I cannot get the shim to work with a relative path but probably I'm doing something wrong. This is how I would like to import and how the IDE likes it too:

import Foo from '../FolderB/Foo.js'

And then this is what I tried:

Just the name of the module

"browserify-shim": {
        "Foo": "global:Foo"
    }

Same path as import path:

"browserify-shim": {
        "../FolderB/Foo.js": "global:Foo"
    }

Path relative to this package.json file

"browserify-shim": {
        "./src/FolderB/Foo.js": "global:Foo"
    }

With all the above options, the shim doens't work. I verified this by looking in the output javascript file. With the configuration as explained in my first post, the whole class inside Foo disappears from the output which is what I expect.

Any idea?