Bug 242936 - editors/vscode: Fails to build: yarn attempts to fetch dependency in offline mode (typscript)
Summary: editors/vscode: Fails to build: yarn attempts to fetch dependency in offline ...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Hiroki Tagato
URL:
Keywords: needs-patch, needs-qa
Depends on:
Blocks:
 
Reported: 2019-12-28 08:01 UTC by bourne.identity@hotmail.com
Modified: 2022-07-09 01:55 UTC (History)
7 users (show)

See Also:
tagattie: maintainer-feedback+


Attachments
log for build failure of vscode (11.94 KB, text/plain)
2019-12-28 10:19 UTC, bourne.identity@hotmail.com
no flags Details
log for patch and build of vscode (3.75 KB, text/plain)
2019-12-30 09:31 UTC, bourne.identity@hotmail.com
no flags Details
Fix build on base system with ${LOCALBASE}/share/.yarnrc existing (1.05 KB, patch)
2022-06-26 11:42 UTC, Stefan Eßer
no flags Details | Diff
Fix build on base system with ${LOCALBASE}/share/.yarnrc existing (1.07 KB, patch)
2022-06-26 12:56 UTC, Stefan Eßer
tagattie: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description bourne.identity@hotmail.com 2019-12-28 08:01:51 UTC
Hi,

On an 12.1 AMD64 box, I am trying to build editors/vscode from ports with all default config options on.


After a few hours of compilation, I get this :


<<

$ yarn --frozen-lockfile --offline
yarn install v1.16.0
warning package.json: No license field
warning vscode-extensions@0.0.1: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
error Can't make a request in offline mode ("https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz")
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

>>
Comment 1 Hiroki Tagato freebsd_committer freebsd_triage 2019-12-28 10:12:20 UTC
(In reply to bourne.identity@hotmail.com from comment #0)

Can you post a while build log?
It appears yarn somehow can't find modules cache location.
Comment 2 bourne.identity@hotmail.com 2019-12-28 10:19:33 UTC
Created attachment 210277 [details]
log for build failure of vscode

Attached is the log for build failure of vscode.
Comment 3 Hiroki Tagato freebsd_committer freebsd_triage 2019-12-29 11:48:21 UTC
(In reply to bourne.identity@hotmail.com from comment #2)

There is nothing suspicious in the build log and I can't reproduce the error.

Does the file "typescript-3.7.3.tgz", which yarn tries to download, exist in ${WRKDIR}/yarn-offline-cache?
Comment 4 bourne.identity@hotmail.com 2019-12-29 12:33:55 UTC
Yes, it does on my system.
Comment 5 Hiroki Tagato freebsd_committer freebsd_triage 2019-12-30 07:42:32 UTC
(In reply to bourne.identity@hotmail.com from comment #4)

I still can't reproduce the error. But can you try the following procedure?

1. make patch

2. edit ${WRKSRC}/.yarnrc
Change the line:
yarn-offline-mirror "/usr/ports/editors/vscode/work/yarn-offline-cache"
to:
yarn-offline-mirror "../yarn-offline-cache"

3. make build

Accoding to the URL: https://yarnpkg.com/en/docs/yarnrc#toc-yarn-offline-mirror, the value of "yarn-offline-mirror" must be a relative path and having used an absolute path may have something to do with the error.
Comment 6 bourne.identity@hotmail.com 2019-12-30 09:31:52 UTC
Created attachment 210325 [details]
log for patch and build of vscode

No, doesn't work for me.

1) Ran 'make patch'
2) There is no ${WRKSRC}/.yarnrc but there is a work/vscode-1.41.0/.yarnrc. I patched that file. I presume you meant the same.
3) Ran 'make build'

I get pretty much the same error as before. Kindly refer attachment.
Comment 7 bourne.identity@hotmail.com 2019-12-30 10:26:16 UTC
I now think the problem is not with the port but with my system. Before building the port, I had git cloned vscode from the web and then ran 'make install' inside the cloned directory. That build failed with a different sequence of errors, but I think installed many binaries and modules including yarn and node on my system. These would conflict with the standard /usr/ports/editors/vscode port. So when I run 'make install' inside the port, I am almost certain to get unpredictable results. I deleted as many previously standing modules (yarn, node) from the git clone, but continue to get the same error when I run 'make install' inside the port.

You certainly would not be able to reproduce the error I get and probably should mark this bug request as closed. If you could still give me a tip how I can recover from this disaster, I shall be grateful.

Thanks,
Manish Jain
Comment 8 Hiroki Tagato freebsd_committer freebsd_triage 2019-12-30 12:05:07 UTC
(In reply to bourne.identity@hotmail.com from comment #7)

I'm not sure but the system-wide yarn cache may have something to do with the error.

Can you try "yarn cache clean" before "make install"?
Comment 9 bourne.identity@hotmail.com 2019-12-30 13:17:54 UTC
Does not work in numerous ways I tried. I probably will have to wait for vscode pkg to become available. Any further tips are welcome. I also sent a related question to freebsd-questions, which I separately emailing to you.

Thanks,
Manish Jain
Comment 10 Hiroki Tagato freebsd_committer freebsd_triage 2019-12-30 13:48:45 UTC
(In reply to bourne.identity@hotmail.com from comment #9)

Try again to set POUDRIERE option OFF (using make config) and "make install".

That will allow yarn to access network during build. So the "offline mode" error should go away by the workaround.
Comment 11 bourne.identity@hotmail.com 2019-12-30 14:26:28 UTC
Very, very close to success. vscode builds nicely but the installation fails:

===>  Installing for vscode-1.41.0
===>  Checking if vscode is already installed
===>   Registering installation for vscode-1.41.0
pkg-static: Unable to access file /usr/ports/editors/vscode/work/stage/usr/local/share/code-oss/resources/app/extensions/ms-vscode.references-view/dist/extension.js.map:No such file or directory
*** Error code 74

Stop.
make[1]: stopped in /usr/ports/editors/vscode
*** Error code 1
Comment 12 bourne.identity@hotmail.com 2019-12-30 14:33:44 UTC
I also checked the dist directory (/usr/ports/editors/vscode/work/stage/usr/local/share/code-oss/resources/app/extensions/ms-vscode.references-view/dist). The file extension.js exists, but extension.js.map does not exist.
Comment 13 Hiroki Tagato freebsd_committer freebsd_triage 2020-01-01 06:43:37 UTC
Just FYI, a binary package of vscode is already available in the latest branch of pkg set.
(See http://pkg.freebsd.org/FreeBSD:12:amd64/latest/All/)

I guess vscode pkg will be available shortly in the quarterly (default) branch as well.

If you want to try the pkg now and don't mind switching to the latest branch, try the steps at:
https://wiki.freebsd.org/Ports/QuarterlyBranch (Switching from quarterly to latest)
Comment 14 bourne.identity@hotmail.com 2020-01-03 20:04:56 UTC
'pkg add' of the latest txz worked. Thanks !
Comment 15 Luca Pizzamiglio freebsd_committer freebsd_triage 2020-03-21 15:58:40 UTC
May I close this bug?
Comment 16 bourne.identity@hotmail.com 2020-03-21 16:28:35 UTC
Sure. Please go ahead.
Comment 17 Jacques Foucry 2021-02-14 16:29:44 UTC
Hello, 

Seems to came back with latest version (1.53.2):

I had to change `/usr/ports/editors/vscode/work/vscode-1.53.2/build/npm/postinstall.js` file, line 24 from:

```
const passargs = ['--ignore-optional', '--frozen-lockfile', '--ofiline-mode', '--no-progress', '--verbose'];

```
into
```
const passargs = ['--ignore-optional', '--frozen-lockfile', '--no-progress', '--verbose'];
```

IE, remode `--offline-mode``

Sorry to reopen this issue.

Jacques Foucry
Comment 18 Hiroki Tagato freebsd_committer freebsd_triage 2021-02-15 07:49:51 UTC
(In reply to Jacques Foucry from comment #17)

I can't reproduce the error by doing "make build" or building with poudriere. Can you share how you tried to build the port?

FYI:
It was reported recently a similar issue was resolved by "doing full clean-up of /usr/local and rebuilding all packages."
https://lists.freebsd.org/pipermail/freebsd-ports/2021-February/120289.html
Comment 19 Koichiro Iwao freebsd_committer freebsd_triage 2021-02-19 14:58:07 UTC
I also encountered the same issue now.
Comment 20 Koichiro Iwao freebsd_committer freebsd_triage 2021-02-19 16:33:37 UTC
"make clean configure make-yarn-cache clean build" did the trick for me.
Comment 21 Koichiro Iwao freebsd_committer freebsd_triage 2021-04-08 00:26:04 UTC
(In reply to Koichiro Iwao from comment #20)

After the recent update to 1.55.0, I encountered this issue again.
Performing "make configure make-yarn-cache" did the trick again.
Comment 22 Stefan Eßer freebsd_committer freebsd_triage 2022-06-26 11:42:43 UTC
Created attachment 234950 [details]
Fix build on base system with ${LOCALBASE}/share/.yarnrc existing

Building editors/vscode on the base system fails if other ports have created a file ${LOCALBASE}/share/.yarnrc that defines yarn-offline-cache overriding the .yarnrc definition of this port.

I did not check why this is not an issue for build/npm/preinstall.js, but build/npm/postinstall.js prefers the .yarnrc in ${LOCALBASE}/share and then fails to find the required dependencies in ${LOCALBASE}/share/yarn-offline-cache.

The attached patch makes yarn use the port's .yarnrc instead of the one in the base system directory and thus fixes the build in the scenario outlined above.
Comment 23 Hiroki Tagato freebsd_committer freebsd_triage 2022-06-26 12:14:27 UTC
(In reply to Stefan Eßer from comment #22)

Thanks a lot for the patch!

Could you tell me which port have created ${LOCALBASE}/share/.yarnrc so that I can double-check the issue has been solved? (I grep'ed the ports directory but could not find a pkg-plist containing .yarnrc.)
Comment 24 Stefan Eßer freebsd_committer freebsd_triage 2022-06-26 12:56:18 UTC
Created attachment 234951 [details]
Fix build on base system with ${LOCALBASE}/share/.yarnrc existing

The previous patch used a relative path to the .yarnrc file, which did not work in sub-directories of "extensions".

Update to use an absolute path instead.
Comment 25 Stefan Eßer freebsd_committer freebsd_triage 2022-06-26 13:34:27 UTC
(In reply to Hiroki Tagato from comment #23)

I do not know which port might have created /usr/local/share/.yarnrc and fetched the files into /usr/local/share/yarn-offline-cache.

Since I had removed "--offline" from the vscode build before, there were a number of vscode dependencies (dating back to 2020, since I had used the work-around since then).

I'll watch these locations to see whether they are recreated when I update other ports that use yarn.

But I have verified that moving /usr/local/share/.yarnrc out of the way fixes the vscode build, as does commenting out setting the yarn cache variable in that file.

Passing the path to the correct .yarnrc fixes the issue in any case, independently if other .yarnrc files on the system.

But IMHO no port should put files into /usr/local/share without those file being registered in the package database, much less files that are only required at build time. I'll open PRs for those other ports that put files into those directories ...
Comment 26 Hiroki Tagato freebsd_committer freebsd_triage 2022-06-27 07:04:36 UTC
(In reply to Stefan Eßer from comment #24)

Great! I double-checked the patch works on my environment.

Would you like to commit the patch?
Comment 27 commit-hook freebsd_committer freebsd_triage 2022-07-09 01:54:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5b2cbb7be2922fb35dd827a4a17ab1c04c23db58

commit 5b2cbb7be2922fb35dd827a4a17ab1c04c23db58
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2022-07-09 01:51:16 +0000
Commit:     Hiroki Tagato <tagattie@FreeBSD.org>
CommitDate: 2022-07-09 01:51:16 +0000

    editors/vscode: fix build with ${LOCALBASE}/share/.yarnrc existing

    PR:             242936
    Reported by:    bourne.identity@hotmail.com,
                    jacques+freebsdbugzilla@foucry.net,
                    meta

 editors/vscode/files/patch-build_npm_postinstall.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 28 Hiroki Tagato freebsd_committer freebsd_triage 2022-07-09 01:55:17 UTC
Committed, thanks!