Upgrading to Stencil v4.0.0
Getting Started
We recommend that you only upgrade to Stencil v4 from Stencil v3. If you're a few versions behind, we recommend upgrading one major version at a time (from v1 to v2, then v2 to v3, finally v3 to v4). This will minimize the number of breaking changes you have to deal with at the same time.
For breaking changes introduced in previous major versions of the library, see:
For projects that are on Stencil v3, install the latest version of Stencil v4: npm install @stencil/core@4
Updating Your Code
New Configuration Defaults
Starting with Stencil v4.0.0, the default configuration values have changed for a few configuration options. The following sections lay out the configuration options that have changed, their new default values, and ways to opt-out of the new behavior (if applicable).
transformAliasedImportPaths
TypeScript projects have the ability to specify a path aliases via the paths
configuration in their tsconfig.json
like so:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@utils": ["src/utils/index.ts"]
}
}
}
In the example above, "@utils"
would be mapped to the string "src/utils/index.ts"
when TypeScript performs type resolution.
The TypeScript compiler does not however, transform these paths from their keys to their values as a part of its output.
Instead, it relies on a bundler/loader to do the transformation.
The ability to transform path aliases was introduced in Stencil v3.1.0 as an opt-in feature.
Previously, users had to explicitly enable this functionality in their stencil.config.ts
file with transformAliasedImportPaths
:
import { Config } from '@stencil/core';
export const config: Config = {
transformAliasedImportPaths: true,
// ...
};
Starting with Stencil v4.0.0, this feature is enabled by default. Projects that had previously enabled this functionality that are migrating from Stencil v3.1.0+ may safely remove the flag from their Stencil configuration file(s).
For users that run into issues with this new default, we encourage you to file a new issue on the Stencil GitHub repo.
As a workaround, this flag can be set to false
to disable the default functionality.
import { Config } from '@stencil/core';
export const config: Config = {
transformAliasedImportPaths: false,
// ...
};
For more information on this flag, please see the configuration documentation
transformAliasedImportPathsInCollection
Introduced in Stencil v2.18.0, transformAliasedImportPathsInCollection
is a configuration flag on the dist
output target.
transformAliasedImportPathsInCollection
transforms import paths, similar to transformAliasedImportPaths
.
This flag however, only enables the functionality of transformAliasedImportPaths
for collection output targets.
Starting with Stencil v4.0.0, this flag is enabled by default. Projects that had previously enabled this functionality that are migrating from Stencil v2.18.0+ may safely remove the flag from their Stencil configuration file(s).
For users that run into issues with this new default, we encourage you to file a new issue on the Stencil GitHub repo.
As a workaround, this flag can be set to false
to disable the default functionality.
import { Config } from '@stencil/core';
export const config: Config = {
outputTargets: [
{
type: 'dist',
transformAliasedImportPathsInCollection: false,
},
// ...
]
// ...
};
For more information on this flag, please see the dist
output target's documentation.
In Browser Compilation Support Removed
Prior to Stencil v4.0.0, components could be compiled from TSX to JS in the browser. This feature was seldom used, and has been removed from Stencil. At this time, there is no replacement functionality. For additional details, please see the request-for-comment on the Stencil GitHub Discussions page.
Legacy Context and Connect APIs Removed
Previously, Stencil supported context
and connect
as options within the @Prop
decorator.
Both of these APIs were deprecated in Stencil v1 and are now removed.
@Prop({ context: 'config' }) config: Config;
@Prop({ connect: 'ion-menu-controller' }) lazyMenuCtrl: Lazy<MenuController>;
To migrate away from usages of context
, please see the original deprecation announcement.
To migrate away from usages of connect
, please see the original deprecation announcement.
Legacy Browser Support Removed
In Stencil v3.0.0, we announced the deprecation of IE 11, pre-Chromium Edge, and Safari 10 support. In Stencil v4.0.0, support for these browsers has been dropped (for a full list of supported browsers, please see our Browser Support policy).
By dropping these browsers, a few configuration options are no longer valid in a Stencil configuration file:
__deprecated__cssVarsShim
The extras.__deprecated__cssVarsShim
option caused Stencil to include a polyfill for CSS variables.
This field should be removed from a project's Stencil configuration file (stencil.config.ts
).