crazyfactory/tslint-rules

The "main" entry point is missing

Closed this issue ยท 8 comments

Hello and thank you for your work.

When trying to include one of your rules in my TSLint setup, my build fails because of what I believe to be a bug.

Cannot find module '<path/to/my/project>/node_modules/@crazyfactory/tslint-rules/lib/index.js'. Please verify that the package.json has a valid "main" entry

When we look at the contents of node_modules, the lib/index.js file is missing indeed.

image

However, it should be there as declared in package.json.

"main": "./lib/index.js",

I believe the solution is to put a barrel file in src so it's preserved in the transpiled output. If you agree, I can take submit a PR doing exactly that.

@paibamboo knows more on this as he has worked on it more than myself, but this shouldn't be happening, I mean, all you need to do is to provide a rules_directory on your tslint or eslintrc file,

the error message you're getting is probably because you're trying to import or require from this project. Which isn't the usecase AFAIK.

Can you tell exactly what it is that you're looking for? if you want to import something, you can do so by doing /lib/<file> Are you trying to import this and do something on top?

I took a look at tslint-react and tslint-microsoft-contrib, their main is json file instead of js file. Not sure what that means.

I figured it out. Those are some preset rules to be extended by consumer. I think we should do the same.

@karol-majewski Are you still willing to send a pr if the direction is to change main to json file instead of js file? What is your use case that you need to import from the library thus encountering that Cannot find module error?

the error message you're getting is probably because you're trying to import or require from this project. Which isn't the usecase AFAIK.

Close to it. My package is a collection of rules with a shared config. It allows me to import a single dependency like my-tslint-config instead of installing every constituent package in every project I work on.

My package exports something like this:

module.exports = {
  rulesDirectory: [
    getRulesDirectory('tslint-eslint-rules', 'dist/rules'),
    getRulesDirectory('tslint-consistent-codestyle'),
    getRulesDirectory('tslint-microsoft-contrib'),
    getRulesDirectory('vrsource-tslint-rules', 'rules'),
    getRulesDirectory('tslint-misc-rules'),
    getRulesDirectory('custom-tslint-rules', 'dist'),
    getRulesDirectory('tslint-plugin-blank-line'),
    getRulesDirectory('dtslint', 'rules'),
    getRulesDirectory("rxjs-tslint"),
    getRulesDirectory("tslint", 'rules'),
    getRulesDirectory('@crazyfactory/tslint-rules', 'lib')
  ],
  extends: [
    "tslint:latest",
    "tslint-react",
    "tslint-immutable",
    "tslint-consistent-codestyle",
    "tslint-clean-code",
    "tslint-eslint-rules",
    "tslint-sonarts",
    "tslint-no-circular-imports",
  ],
  rules: {
    ...legacy.rules,
    ...experimental.rules,
  }
};

As you can see, there's a lot of packages, so having one to wrap them all comes in handy.

So far, it worked perfectly fine. I was able to getRulesDirectory from every package because every package on the list has a folder where transpiled rules are kept. @crazyfactory/tslint-rules does have a directory like that as well, but for some reason, I cannot import from it.

I took a look at tslint-react and tslint-microsoft-contrib, their main is json file instead of js file. Not sure what that means.

I looked at some other packages and it seems like this is the way to go. That's also what the documentation suggests.

So far, it worked perfectly fine. I was able to getRulesDirectory from every package because every package on the list has a folder where transpiled rules are kept. @crazyfactory/tslint-rules does have a directory like that as well, but for some reason, I cannot import from it.

From the error message Please verify that the package.json has a valid "main" entry I can only guess that our package.json doesn't have a valid main entry yet..

I think the json file is a good one, that way we can simply "extend" with @crazyfactory/tslint-rules and that should still fit @karol-majewski 's use case because he's already using tslint-microsoft-contrib and if that's working and we do the same, ours should also work

๐ŸŽ‰ This issue has been resolved in version 1.8.1 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€