less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
17.02k stars 3.41k forks source link

3.11.0 Cannot find module 'tslib' #3469

Closed xiaohuyahappy closed 4 years ago

xiaohuyahappy commented 4 years ago

Cannot find module 'tslib' 3.11.0

mpibpc-mroose commented 4 years ago

I can acknowledge the problem. It came up with the newest version, 3.10.3 worked fine. Maybe @matthew-dean could check the last merge?

Steps to reproduce with docker

  1. create a new folder
  2. place some test.lesscontaining valid less code there
  3. create a Dockerfile with following content:
    
    FROM buildpack-deps:buster

COPY test.less /

install npm

ENV HOME /root RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - RUN apt-get install -y nodejs

install less and compile something

RUN npm install -g less WORKDIR / RUN lessc test.less test.css

4. Call `docker build .` in the folder

This will cause the following error:

Step 6/8 : RUN npm install -g less ---> Running in a76855c18efa /usr/bin/lessc -> /usr/lib/node_modules/less/bin/lessc

Error: Cannot find module 'tslib' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (/usr/lib/node_modules/less/bin/lessc:9:13) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) The command '/bin/sh -c lessc test.less test.css' returned a non-zero code: 1

dgavril commented 4 years ago

Also reproducible with grunt-contrib-less ("grunt-contrib-less": "2.0.0") which uses "less": "^3.0.4". A gulp issue was reported too.

siimots commented 4 years ago

3.11.0 was such a big update. Should have been 4.0.0

arcanis commented 4 years ago

Also triggered errors on the Yarn E2E testsuite (we use that to monitor various projects): https://github.com/yarnpkg/berry/runs/436357016

I suspect the project just needs to add a dependency to tslib - people tend to forget to explicitly list it because the source files don't reference it, only the build artifacts do.

matthew-dean commented 4 years ago

Well shoot, sorry all. The build was passing unit tests, so I guess there was a missing test here.

@siimots

3.11.0 was such a big update. Should have been 4.0.0

Not really, in terms of semver. There should be no backwards-incompatible changes, just changes to some build settings. I'll check it out shortly.

matthew-dean commented 4 years ago

@arcanis

I suspect the project just needs to add a dependency to tslib - people tend to forget to explicitly list it because the source files don't reference it, only the build artifacts do.

Probably the reason this happened is because tslib might be an implicit dependency (dependency of a dependency) in the devDependencies. So tests would pass but a normal npm install wouldn't install it.

boutell commented 4 years ago

+1, also seeing this with apostrophecms. Looks like this will be getting fixed quickly, thank you.

matthew-dean commented 4 years ago

As an aside, if anyone knows of a reliable method to simulate / test a library install as a dependency and run tests without the need to wipe / reinstall node modules, I'd love to hear it.

arcanis commented 4 years ago

@matthew-dean Fwiw this kind of issue is one of the reasons we introduced Plug'n'Play in Yarn. It throws exceptions when packages make unsafe accesses (such as tslib here) instead of letting them mistakenly succeed. Of course it requires to use Yarn since npm doesn't support it, so it may not be what you're looking for 🙂

To give you an example, this is what the test I linked reported:

image

matthew-dean commented 4 years ago

Can someone verify that this build is fixing things? https://github.com/less/less.js/tree/release-3.11.1

boutell commented 4 years ago

You can have node_modules folders nested anywhere. So you can put one in your test/ folder that is only used for this purpose and is more convenient to blow up. We do this with apostrophe.

On Mon, Feb 10, 2020 at 4:37 PM Matthew Dean notifications@github.com wrote:

Can someone verify that this build is fixing things? https://github.com/less/less.js/tree/release-3.11.1

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/less/less.js/issues/3469?email_source=notifications&email_token=AAAH27IM5UVBLOEMPE5BJR3RCHCJBA5CNFSM4KSHHJ62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELKMI5A#issuecomment-584369268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27OZWO622K5JYHEYNCLRCHCJBANCNFSM4KSHHJ6Q .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

boutell commented 4 years ago

Inside that you can have a symlink to find the main folder of the module by the right name.

On Mon, Feb 10, 2020 at 5:02 PM Tom Boutell tom@apostrophecms.com wrote:

You can have node_modules folders nested anywhere. So you can put one in your test/ folder that is only used for this purpose and is more convenient to blow up. We do this with apostrophe.

On Mon, Feb 10, 2020 at 4:37 PM Matthew Dean notifications@github.com wrote:

Can someone verify that this build is fixing things? https://github.com/less/less.js/tree/release-3.11.1

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/less/less.js/issues/3469?email_source=notifications&email_token=AAAH27IM5UVBLOEMPE5BJR3RCHCJBA5CNFSM4KSHHJ62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELKMI5A#issuecomment-584369268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27OZWO622K5JYHEYNCLRCHCJBANCNFSM4KSHHJ6Q .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

jmwolfe commented 4 years ago

@matthew-dean ... how can i change my package.json file to try out your new release? I still am only able to pull down 3.11.0 if I don't specify a version.

matthew-dean commented 4 years ago

@boutell That's not the most clear description. Do you mean setting up some sort of sub-package in the repo? I'm wondering how you do this in a way that won't encounter Node's parent node_modules resolution algorithm.

@jmwolfe

https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

boutell commented 4 years ago

Hmm. No, you're right, that doesn't quite suit your situation. The only sure thing I can think of would be setting up a local npm proxy in which that particular module is satisfied from your own location, and testing npm install against that. Local npm proxies like this are actually not hard to come by but it is kind of a lot.

On Mon, Feb 10, 2020 at 5:10 PM Matthew Dean notifications@github.com wrote:

@boutell https://github.com/boutell That's not the most clear description. Do you mean setting up some sort of sub-package in the repo? I'm wondering how you do this in a way that won't encounter Node's parent node_modules resolution algorithm.

@jmwolfe https://github.com/jmwolfe

https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/less/less.js/issues/3469?email_source=notifications&email_token=AAAH27O3T4O2Z7VPTBA6HYLRCHGEPA5CNFSM4KSHHJ62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELKPPYQ#issuecomment-584382434, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27JP6LEUZIENWBEWERLRCHGEPANCNFSM4KSHHJ6Q .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

jmwolfe commented 4 years ago

@matthew-dean - using this in my package.json works to fix gulp-less which depends on less:

"dependencies": {
    "less": "git://github.com/less/less.js.git#afc9b86"
}

# npm list less
xxxx@1.0.0 C:\SVN\CMGR\branches\cmgr_pmm2\ContentManager\ContentManager            
+-- gulp-less@4.0.1                                                                           
| `-- less@3.11.1  deduped (git://github.com/less/less.js.git#afc9b8606272a01bf4392f71e4d9db59d06fddb9)                                                                                     
`-- less@3.11.1  (git://github.com/less/less.js.git#afc9b8606272a01bf4392f71e4d9db59d06fddb9) 

my resulting gulpfile.js loads perfectly.

ps. gulp-less and a few other packages are in devDependencies.

boutell commented 4 years ago

Great, thank you! Is this published to npm?

On Tue, Feb 11, 2020 at 12:53 AM Matthew Dean notifications@github.com wrote:

Closed #3469 https://github.com/less/less.js/issues/3469 via 842386b https://github.com/less/less.js/commit/842386b8db5cb5afa4edf5a4c81d40bcbf47a6a2 .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/less/less.js/issues/3469?email_source=notifications&email_token=AAAH27NPPJXO4IOUM2I2J3LRCI4NLA5CNFSM4KSHHJ62YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOWRJHA5I#event-3025301621, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27I5LOTWY22VMC57QFLRCI4NLANCNFSM4KSHHJ6Q .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

jmwolfe commented 4 years ago

@boutell yes it is. I just verified.

boutell commented 4 years ago

👍 thanks for all you do!

On Tue, Feb 11, 2020 at 12:18 PM Jesse Wolfe notifications@github.com wrote:

@boutell https://github.com/boutell yes it is. I just verified.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/less/less.js/issues/3469?email_source=notifications&email_token=AAAH27P3RR4ZWL6PXZHC7N3RCLMXRA5CNFSM4KSHHJ62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELNIUHY#issuecomment-584747551, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27MKPLJTLBZ5NLHZWALRCLMXRANCNFSM4KSHHJ6Q .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

SOHELAHMED7 commented 5 months ago

For those who were still facing the issue

I was using Ubuntu 22.04 when I faced this issue.

Node, npm are installed in Ubuntu in several ways.

1st way: Ubuntu package manager sudo apt-get install ...

sudo apt-get install nodejs npm 

See nodejs, npm and node-less at https://packages.ubuntu.com/

There is no package for node but there is one for nodejs. In order to properly install less this way use

sudo apt-get install nodejs npm node-less

2nd way: nvm

# installs NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js
nvm install 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.12.2`
# verifies the right NPM version is in the environment
npm -v # should print `10.5.0`

source

Note that this automatically installs npm. In order to properly install less this way use

 npm install -g lessc

Here we don't have any package for nodejs


Node and npm installed by both of the above way will be different. Use only one at a time. This will have dependencies installed properly. Using 2nd approach using nvm is recommended.