Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve own package within TypeScript Lerna Repo #1708

Closed
Anupheaus opened this issue Jun 13, 2018 · 3 comments
Closed

Unable to resolve own package within TypeScript Lerna Repo #1708

Anupheaus opened this issue Jun 13, 2018 · 3 comments

Comments

@Anupheaus
Copy link

Issue description or question

I am using Yarn with workspaces enabled, Lerna, TypeScript and React in this project.

I have looked at all the issues surrounding this topic in wallabyjs/public and I cannot find a solution that works. I am using react but using enzyme for testing. It is failing in my setup.ts on this line:

import '@myapp/common';

Where Lerna has added @myapp/packagename to the node_modules folder at the root, so it should find it easily?

Wallaby.js configuration file

const path = require('path');

module.exports = function (wallaby) {
  process.env.NODE_PATH = (process.env.NODE_PATH || '') + path.delimiter + path.join(wallaby.projectCacheDir, 'packages');
  return {
    files: [
      { pattern: 'react', ignore: true },
      { pattern: 'react-dom', ignore: true },
      { pattern: 'packages/ui/src/**/*.tests.ts?(x)', ignore: true },
      { pattern: 'packages/ui/tests/environment.ts', load: false, instrument: false },
      { pattern: 'packages/ui/tests/setup.ts', load: false, instrument: false },
      { pattern: 'packages/*/src/**/*.ts?(x)', load: false },
    ],
    tests: [
      { pattern: './packages/ui/src/**/*.tests.ts?(x)' },
    ],
    testFramework: 'mocha',
    env: {
      type: 'node',
      runner: 'node',
    },
    workers: {
      initial: 1,
      regular: 1,
      recycle: true,
    },
    setup() {
      require('./packages/ui/tests/setup');
    },
  };
}

Code editor or IDE name and version

Visual Studio Code v1.24.0?

OS name and version

Windows 10

@ArtemGovorov
Copy link
Member

Thanks for providing the details.
You may find the solution here: #1665 (comment). In your case it will look like:

setup() {
  require('module-alias').addAliases({ '@myapp': w.projectCacheDir + '/packages' });
  ...
}

@Anupheaus
Copy link
Author

This still doesn't exactly work, I have to change a file pattern to this:

{ pattern: 'packages/**/*.ts?(x)', load: false }

and add an index.ts file in the root of each package exporting everything from the ./src folder to get this to work, or I would have to put the individual packages all explicitly in the addAliases method like so: .addAliases({ '@myapp/common': w.projectCacheDir + '/packages/common/src' }).

Any ideas on how to get the aliasing to work without having to explicitly set each alias or without having to add an index file in the package root folder please?

@ArtemGovorov
Copy link
Member

This:

setup() {
  require('module-alias').addAliases({ '@myapp': w.projectCacheDir + '/packages' });
  ...
}

should be enough. However, since you have main field pointing to src in your packages package.json files, you'll need to let Wallaby know about your package.json files (otherwise standard node resolution is used as if package.json was missing). So adding:

{ pattern: 'packages/**/package.json', load: false },

should work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants