创建Angular代码共享项目未生成webpack文件的问题咨询
Hey there! As someone who’s navigated NativeScript’s quirks as a newbie, let me break this down clearly for you:
1. Is the missing webpack.config.js intentional for code-shared projects?
Yes, totally! When you create a code-shared project with the --shared flag, the template does not generate a root-level webpack.config.js by design.
NativeScript revamped its build toolchain starting around version 8.x, moving away from exposing explicit webpack config files for code-shared projects. Instead, webpack configuration is integrated directly into the NativeScript CLI and schematics—this was done to simplify setup for developers who want to focus on cross-platform code rather than tinkering with build configs.
2. Why are tns preview --bundle or tns run android --bundle failing?
The --bundle flag is outdated now! From NativeScript 8.x onwards, bundle mode is enabled by default—you don’t need to add that flag anymore. Running just tns preview or tns run android should work without specifying --bundle.
If you’re still seeing errors, it’s likely a version mismatch between your NativeScript CLI, @nativescript/schematics, and project dependencies. Older versions might still expect the explicit webpack config file that’s no longer generated.
3. What’s wrong with manually installing nativescript-dev-webpack?
That package is deprecated! NativeScript has moved away from standalone nativescript-dev-webpack and now uses a built-in webpack toolchain. Installing this old package will cause dependency conflicts, which explains the deprecated module warnings and your Android app crashes. Do not use this package with modern code-shared projects.
4. Fixes to get your project running smoothly
- Update your NativeScript CLI: First, make sure you’re on the latest stable version. Run:
Verify withnpm install -g nativescripttns --version—aim for version 8.x or higher. - Recreate your project (if starting fresh): Use the exact command you ran before, but skip any manual webpack installs:
ng new --collection=@nativescript/schematics project-name --shared - Migrate an existing project: If you don’t want to start over, run the migration command to update your project’s dependencies and build config to match the latest toolchain:
tns migrate - Check your core config file: Instead of
webpack.config.js, your project now usesnativescript.config.ts(or.js) as the central config hub. Any webpack tweaks you need can be added here using thewebpackConfigproperty, which lets you extend the internal webpack setup without a separate file.
Final Note
Once you’ve updated everything, running tns preview should load your app in the browser preview app, and tns run android will deploy to your device/emulator without bundle-related errors.
内容的提问来源于stack exchange,提问作者Kromah

