Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
Hi,
I have installed node module "@apollo/client" from npm install, i am trying to use that in scripts.js file, using import, but getting error in browser console "Uncaught TypeError: Failed to resolve module specifier "@apollo/client". Relative references must start with either "/", "./", or "../""
I am new to AEM edge delivery services, please let me know what am missing.
Thanks,
Parvathi
Gelöst! Gehe zu Lösung.
Anhand von Themen werden Community-Inhalte kategorisiert und Sie können so relevanten Inhalt besser finden.
@ParvathiSo1 The root cause of your issue is that browsers cannot directly resolve bare module specifiers like @apollo/client. Unlike Node.js, which has a built-in module resolution system that understands npm package names, browsers require either:
For Edge Delivery Services (EDS) projects, the best approach is to use a module bundler in your build process:
# Add bundling dependencies
npm install --save-dev rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs
Then create a rollup configuration file (rollup.config.js😞
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
input: 'src/scripts.js',
output: {
file: 'scripts/scripts.js',
format: 'es'
},
plugins: [
resolve(),
commonjs()
]
};
Add a build script to your package.json:
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w"
}
Note that the "rollup.config.js" needs to be placed in your project root folder.
@ParvathiSo1 The root cause of your issue is that browsers cannot directly resolve bare module specifiers like @apollo/client. Unlike Node.js, which has a built-in module resolution system that understands npm package names, browsers require either:
For Edge Delivery Services (EDS) projects, the best approach is to use a module bundler in your build process:
# Add bundling dependencies
npm install --save-dev rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs
Then create a rollup configuration file (rollup.config.js😞
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
input: 'src/scripts.js',
output: {
file: 'scripts/scripts.js',
format: 'es'
},
plugins: [
resolve(),
commonjs()
]
};
Add a build script to your package.json:
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w"
}
Note that the "rollup.config.js" needs to be placed in your project root folder.
Zugriffe
Likes
Antworten