I tried to import react-native-lyric inside MUI box but got error shown below when I run npm web start
.
Failed to compile.
Module parse failed: Unexpected token (1:7)
File was processed with these loaders:
* ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
> export type {LrcLine} from './constant';
|
| export {default as Lyric} from './components/lyric';
ERROR in ./node_modules/react-native-lyric/src/index.ts 1:7
Module parse failed: Unexpected token (1:7)
File was processed with these loaders:
* ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
> export type {LrcLine} from './constant';
|
| export {default as Lyric} from './components/lyric';
To fix the issue I tried making the following change to package.json
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
">0.2%",
"not dead",
"not op_mini all"
]
}
Run npm cache clean --force
and rm -rf node_modules && rm -f package-lock.json && npm i
still the same error.
2
Answers
I think you can try adding the
babel-loader
to your project if it’s not already included, so install it like belowor
and make sure it is properly configured in your webpack or babel configuration, and also make sure that you have the latest versions of the loaders you are using in your project because outdated loaders might have compatibility issues!
you can update the loaders by running
or
also check your
tsconfig.json
file and make sure that the necessary TypeScript options are set, such as the target version and module resolution!good luck !
It seems like the
react-native-lyric
package you’re trying to import might not be compatible with the version of Node.js you’re using. Check the package’s documentation and the release notes to see if there are any specific requirements or compatibility issues for your Node.js version.Additionally, you might want to try clearing the cache and reinstalling the package using the following commands:
Or if that doesn’t work, try uninstalling and reinstalling the entire package:
And also make sure your Node.js version is the latest that is available:
If you’re still encountering the same error, you can try starting an "Issue" on the package’s GitHub. The owner might be able to provide more insight into the specific issue and provide solutions to resolve it.