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

3.11.0 Cannot find module 'tslib' #3469

Closed
xiaohuyahappy opened this issue Feb 10, 2020 · 20 comments
Closed

3.11.0 Cannot find module 'tslib' #3469

xiaohuyahappy opened this issue Feb 10, 2020 · 20 comments
Assignees

Comments

@xiaohuyahappy
Copy link

Cannot find module 'tslib' 3.11.0

@mpibpc-mroose
Copy link

mpibpc-mroose commented Feb 10, 2020

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
  1. 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
+ less@3.11.0
added 60 packages from 123 contributors in 4.306s
Removing intermediate container a76855c18efa
 ---> b78508030649
Step 7/8 : WORKDIR /
 ---> Running in 6cca70d0d858
Removing intermediate container 6cca70d0d858
 ---> d812408c6ef8
Step 8/8 : RUN lessc test.less test.css
 ---> Running in 6c8ef5fc9408
internal/modules/cjs/loader.js:638
    throw err;
    ^

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.<anonymous> (/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
Copy link

dgavril commented Feb 10, 2020

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
Copy link

siimots commented Feb 10, 2020

3.11.0 was such a big update.
Should have been 4.0.0

@arcanis
Copy link

arcanis commented Feb 10, 2020

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
Copy link
Member

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
Copy link
Member

@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
Copy link

boutell commented Feb 10, 2020

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

@matthew-dean
Copy link
Member

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
Copy link

arcanis commented Feb 10, 2020

@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
Copy link
Member

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

@boutell
Copy link

boutell commented Feb 10, 2020 via email

@boutell
Copy link

boutell commented Feb 10, 2020 via email

@jmwolfe
Copy link

jmwolfe commented Feb 10, 2020

@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
Copy link
Member

@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
Copy link

boutell commented Feb 10, 2020 via email

@jmwolfe
Copy link

jmwolfe commented Feb 11, 2020

@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
Copy link

boutell commented Feb 11, 2020 via email

@jmwolfe
Copy link

jmwolfe commented Feb 11, 2020

@boutell yes it is. I just verified.

@boutell
Copy link

boutell commented Feb 11, 2020 via email

@SOHELAHMED7
Copy link

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.

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

9 participants