question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

chore(typescript): upgrade and switch to nodenext

See original GitHub issue

@petermetz When implementing Iroha V2 support in cactus I encountered some problems with @iroha2/client package. Their team provided some solution, but they require the use of moduleResolution of nodenext. This also requires upgrade of TS to 4.7. We will opt for a package that supports our current moduleResolution/typescript but, just in case and for the future, what is your opinion regarding such change?

Here’s info on nodenext modules: https://www.typescriptlang.org/docs/handbook/esm-node.html

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aldousalvarezcommented, Oct 25, 2022

Hello @petermetz here is the initial report about how much effort it would be to upgrade typescript to 4.7 and switch the moduleResolution to nodeNext

Upgrading the typescript to 4.7

Minor updates on some of the files with few upgrades on its dependencies.

Migrating the moduleResolution to nodeNext

Based on the solution from ECMAScript Modules in Node.js, majority of encountered errors are due to new implementation of import policies. Here are some of the changes that bring a few high-level features that you can see below:

-type in package.json and New Extensions Node.js supports a new setting in package.json called type. “type” can be set to either “module” or “commonjs”.

{ “name”: “my-package”, “type”: “module”, “//”: “…”, “dependencies”: { } } This setting controls whether .js files are interpreted as ES modules or CommonJS modules, and defaults to CommonJS when not set. When a file is considered an ES module, a few different rules come into play compared to CommonJS:

  1. import/export statements and top-level await can be used
  2. relative import paths need full extensions (e.g we have to write import “./foo.js” instead of import “./foo”)
  3. imports might resolve differently from dependencies in node_modules
  4. certain global-like values like require() and __dirname cannot be used directly
  5. CommonJS modules get imported under certain special rules

After switching to nodeNext the errors come in batches with 8 to 12 dependecy errors. I have modified/updated 83 files and added 1 file to declare a package so that it would be imported.

As of now files has been tested using “yarn run test:unit” and “yarn run test:integration”. Based on the latest commit all the test results are equal on the test:unit (15 suits and 151 asserts passed to 15 suits and 151 asserts passed) and with more passing results in test:integration (79 suits and 1491 asserts passed to 80 suits and 1499 asserts passed).

EXAMPLE OF THE CHANGES APPLIED:

Before: import { AppModule } from “./app/app.module”; import { environment } from “./environments/environment”;

After import { AppModule } from “./app/app.module.js”; import { environment } from “./environments/environment.js”;

Before import { RuntimeError } from “run-time-error”;

After const { RuntimeError } = require(“run-time-error”);

  1. (Similar solution used with this issue) Before const { version } = await import(packageFilePath);

After const packageFilePathJson = JSON.parse( readFileSync(packageFilePath, “utf8”), ); const { version } = packageFilePathJson;

Before import { NodeSSH, Config as SshConfig, SSHExecCommandOptions, SSHExecCommandResponse, } from “node-ssh”;

After import { NodeSSH, ConfigGiven as SshConfig, ExecOptions as SSHExecCommandOptions, ExecResult as SSHExecCommandResponse, } from “node-ssh”;

  1. Also tried to use the new “type”; “module” into some of the packages:

examples/cactus-example-carbon-accounting-frontend/package.json examples/cactus-example-supply-chain-frontend/package.json

0reactions
aldousalvarezcommented, Oct 27, 2022

Update from the latest commit:

yarn run test:integration is now having more passing results (from 80 suits and 1499 asserts passed to 83 suites and 1558 asserts passed). based on 79 suits and 1491 asserts passed from clean testing without any changes

Read more comments on GitHub >

github_iconTop Results From Across the Web

chore(deps): update dependency typescript to v4.9.3 #18929
This PR contains the following updates: Package Change Age Adoption Passing Confidence typescript (source) 4.8.4 -> 4.9.3 Release Notes Microsoft/TypeScript ...
Read more >
node.js - Why we need "nodenext" typescript compiler option ...
In the typescript compiler options #module we've a bunch of options including nodenext and esnext , where nodenext is experimental (as of ...
Read more >
Use TypeScript to Build a Node API with Express
This tutorial walks you through building a simple and secure Node application using TypeScript, Express, and Okta.
Read more >
Журнал изменений – SWR - Vercel
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >
Documentation - TypeScript 4.7
In turn, TypeScript supports two new source file extensions: .mts and .cts . ... to "module" when running under --module nodenext / --module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found