Common issues and solutions when using the DAP Design System.
Note: As of version 0.47.2, the DAP Design System no longer uses dynamic imports for Day.js locales. This issue should not occur in current versions. If you're using an older version, consider upgrading.
Legacy Solution (for older versions)
Error Message:
Module parse failed: Unexpected token (3:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
> declare module 'dayjs/locale/*' {Root Cause:
Older versions of the DAP Design System used dynamic imports of Day.js locale files, which caused webpack to encounter TypeScript declaration files (.d.ts) during build time.
Solution for older versions:
Add a webpack IgnorePlugin to ignore all .d.ts files. The exact implementation depends on your build tool:
Add this to your docusaurus.config.ts:
import type { Config } from '@docusaurus/types'
import type { Configuration } from 'webpack'
import webpack from 'webpack'
const config: Config = {
// ... your existing config
plugins: [
function (context, options) {
return {
name: 'webpack-config-plugin',
configureWebpack(config: Configuration, isServer: boolean) {
return {
plugins: [
...(config.plugins || []),
// Ignore TypeScript declaration files, especially from dayjs
new webpack.IgnorePlugin({
checkResource(resource: string) {
// Ignore all .d.ts files
return /\.d\.ts$/.test(resource)
},
}),
],
}
},
}
},
],
}
export default config
Add this to your next.config.js or next.config.mjs:
const webpack = require('webpack')
module.exports = {
webpack: config => {
config.plugins.push(
new webpack.IgnorePlugin({
checkResource(resource) {
// Ignore all .d.ts files
return /\.d\.ts$/.test(resource)
},
}),
)
return config
},
}
You'll need to use react-app-rewired or craco to customize webpack:
With react-app-rewired:
- Install:
npm install react-app-rewired --save-dev - Create
config-overrides.js:
const webpack = require('webpack')
module.exports = function override(config) {
config.plugins.push(
new webpack.IgnorePlugin({
checkResource(resource) {
return /\.d\.ts$/.test(resource)
},
}),
)
return config
}
- Update
package.jsonscripts:- Change
react-scriptstoreact-app-rewired
- Change
With CRACO:
- Install:
npm install @craco/craco --save-dev - Create
craco.config.js:
const webpack = require('webpack')
module.exports = {
webpack: {
configure: config => {
config.plugins.push(
new webpack.IgnorePlugin({
checkResource(resource) {
return /\.d\.ts$/.test(resource)
},
}),
)
return config
},
},
}
- Update
package.jsonscripts:- Change
react-scriptstocraco
- Change
Vite typically handles this automatically, but if you encounter issues, you can configure it in vite.config.ts:
import { defineConfig } from 'vite'
export default defineConfig({
optimizeDeps: {
exclude: ['dayjs/locale/*.d.ts'],
},
build: {
rollupOptions: {
external: id => {
return /\.d\.ts$/.test(id)
},
},
},
})
Why This Happens:
The DAP Design System uses dynamic imports for Day.js locales:
// Dynamic import - works for most bundlers
import(`dayjs/locale/${localeCode}`)
When webpack analyzes these dynamic imports at build time, it:
- Tries to determine all possible import paths
- Encounters both
.jsfiles (which work fine) and.d.tsfiles (TypeScript declarations) - Attempts to parse the
.d.tsfiles as JavaScript modules, causing build failures
The IgnorePlugin tells webpack to skip the .d.ts files entirely, allowing only the .js files to be processed.
Note: Other bundlers like Vite, Rollup, and esbuild handle this automatically and don't require the workaround.
Alternative Solutions:
If you cannot modify webpack configuration, you can:
- Use a different bundler - Vite, Rollup, or esbuild typically handle this automatically
- Import from pre-built dist files - Use the compiled distribution files instead of source files
- Upgrade to latest version - Newer versions use static imports and don't have this issue
If components aren't appearing:
-
Check CSS imports - Ensure you've imported the theme CSS:
<link rel="stylesheet" href="path/to/light.theme.css" /> -
Check JavaScript imports - Ensure the component library is loaded:
import 'dap-design-system' -
Check browser console - Look for JavaScript errors that might prevent component registration
If you see TypeScript errors:
- Ensure types are installed - The package includes TypeScript definitions
- Check tsconfig.json - Ensure
moduleResolutionis set to"node"or"bundler" - Restart TypeScript server - In VS Code:
Cmd+Shift+P→ "TypeScript: Restart TS Server"
If styles aren't applying:
- Check CSS import order - Import theme CSS before component CSS
- Check CSS specificity - Your custom styles might be overridden
- Check CSS variables - Ensure design tokens are properly loaded
If you encounter issues not covered here:
- Check the GitHub Issues
- Review the API Documentation
- Check the Examples for working code samples