5

I have a git clone of an npm package which i have modified that works perfectly when I use yarn link <project name> to add it to a project locally. However, when I push it to GitHub and use yarn add <repo url>#<branch> in the same project instead of yarn link, I get a compilation error indicating that the typescript/ES6 has not compiled:

 SyntaxError Plugin: Unexpected token *

Which relates to this line in the package I am adding:

import * as path from 'path'

How can I get yarn add to compile the typescript/ES6 on the fly from the GitHub version just like yarn link does with the local version?

I'd rather not build it and commit the result to git as that adds an extra compilation step every time, which I or others might forget.

Also for clarity: I'm not building and pushing to npm as it's a fork of a package that I don't own.

Matt Gibson
  • 14,616
  • 7
  • 47
  • 79

2 Answers2

1

You need to build files at some point.

Within this repository yarn build (or any other build instruction if needed). You need to run it each time after you yarn upgrade package-you-import.

For a longer answer, see my answer to How to have npm install a TypeScript dependency from a GitHub URL?.

Piotr Migdal
  • 11,864
  • 9
  • 64
  • 86
0

yarn add does not "compile typescript/ES6 on the fly", it just links proper folders. When yarn add-ing from github, you can always import from repo's src directory:

import * as repo from 'repo/src';
burtek
  • 2,576
  • 7
  • 29
  • 37
  • To clarify, the `import *` line is in the package being liked/added, not in the calling code. As I understand it, `yarn link` also just links folders, but that works fine with the local copy. What I need to understand is how/why the `yarn add` from the repo is not working in the same way, despite the folder structure being unchanged. – Matt Gibson May 29 '19 at 15:30