Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

When using TypeScript dependencies from node_modules are not bundled. #49

Open
danthedaniel opened this issue Mar 16, 2018 · 7 comments

Comments

@danthedaniel
Copy link

danthedaniel commented Mar 16, 2018

None of my required files make it into the bundle if they're from node_modules. I've tracked this down to the function isJs in lib/explore.js:

const isJs = (fileList, path) => {
  const file = fileList.files.get(path);
  return file && file.type === 'javascript';
};

Because my paths are being transformed (eg: js/views/not_found.tsx to js/views/not_found.js) this function does not work correctly. I've been able to fix the issue by changing it to:

const isJs = (fileList, path) => {
  return /\.(js|ts|tsx|jsx)/.test(path);
};

Oddly, this issue only emerged after I switched to a fork of typescript-brunch (specifically this) and when I try to switch back to the official package the problem persists. I've even gone as far as wiping my node_modules folder and redownloading all of my dependencies.

@danthedaniel
Copy link
Author

danthedaniel commented Mar 16, 2018

Perhaps a better solution is to modify the compile() function in lib/fs_utils/source_file.js from brunch

From this -

  compile() {
    const path = this.path = this._realPath;
    // ...
      .then(processFile)
      .then(file => {
        this.type = this.type || file.type || '';
        file.compiled = file.data;
        return file;
      })
      // ...
  }

to this -

  compile() {
    const path = this.path = this._realPath;
    // ...
      .then(processFile)
      .then(file => {
        this.type = this.type || file.type || '';
        file.compiled = file.data;
        file.path = path; // Makes sure that the internally stored path remains unchanged
        return file;
      })
      // ...
  }

@Thorn1089
Copy link

I noticed what I think is this issue when making changes to the typescript-brunch plugin myself. Weirdly, node_modules is included fine with Typescript@2.2.2 or lower, but 2.3.0 and above cause the symptoms described here, where it seems like deppack just doesn't find my imports. Not sure why this would be version-dependent.

@Thorn1089
Copy link

@teaearlgraycold diving further, I think the "real" error is this:

return Object.assign({}, compiled, {
        dependencies,
        type: compiler.type,
        path: compiler.targetExtension ?
          path.replace(extRe, compiler.targetExtension) :
          path,
      });

in fs_utils/pipeline.js in Brunch. It's replacing the path based on the extension (".js") specified by the typescript-brunch plugin, which causes the issue you noted with isJs.

@Thorn1089
Copy link

Aha - it's due to commit 7e99449 on typescript-brunch, which adds the target extension property. That might be why it started happening when you switched to a fork, since the fork you mention seems to be up-to-date with master. It's why my own fork also has this issue. I didn't notice that latest commit hasn't been released, which is why the version from npm install still works fine. I'm opening a corresponding issue on the typescript-brunch repo.

@Thorn1089
Copy link

Thorn1089 commented Jul 17, 2018

See also brunch/brunch#1722 and brunch/typescript-brunch#46

@viviansteller
Copy link

Any news on this? This issue still persists?

@paulmillr
Copy link
Member

You can see the news in this issue. Since noone worked on it, it still persists.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants