Given the example below.
import { QueryClientContract, TransactionClientContract } from '@ioc:Adonis/Lucid/Database'
The use of the colon has confused me and never understood where the imported files could be referenced from.
Given the example below.
import { QueryClientContract, TransactionClientContract } from '@ioc:Adonis/Lucid/Database'
The use of the colon has confused me and never understood where the imported files could be referenced from.
Prefixes for modules have existed for a while, though until recently they didn't affect the module functionality at all (you can read more about this development here). It looks like this specific prefix on these modules was supplied by the installation process for Adonis.js
and given that the toolkit uses custom commands for things like building production versions of your project, it may have some custom processes for e.g. loading minimised versions of a dependency specifically for production builds.
There is not currently a standardised meaning or effect of using a prefix like this, outside of node:
(which restricts imports to core packages and prevents you from accidentally downloading a malicious package by mistake, due to a typo). Some projects use this for internal purposes and it will depend on the specific project what effects the prefix may or may not have.
In addition to this answer.
2021-12-12
Node.js now supports a
node:
protocol for built-in modules...Previously:
import * as fs from 'fs/promises';
Now:import * as fs from 'node:fs/promises';
...What are the benefits of using
node:
module specifiers?It’s immediately clear that a built-in Node.js module is imported. Given how many of them there now are, that’s useful information. There is no risk of a module in node_modules overriding the built-in module. This is especially important whenever Node.js adds a new built-in module.
It's also related to "namespace polluting" subjects, and one of the examples could be C++:
using namespace std;
cout << "Values:";
// std::cout << "Values:";
- What does it mean global namespace would be polluted?;
- What's the problem with "using namespace std;"?.
© 2022 - 2024 — McMap. All rights reserved.
from
value has to be a string constant; it says nothing about the semantics of the string contents. – Amboadonis.js
, but I suspect it has something to do with scoped packages <docs.npmjs.com/about-scopes>. Some tooling might have installed the packages as scoped packages, and node (I am assuming node?) can resolve the package. – Wigwam