-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Rollup #1769
Comments
By modifying the rollup.config.js slightly I've succeeded at bundling without error, however we're not out of the woods yet. import sourcemaps from 'rollup-plugin-sourcemaps';
import resolve from 'rollup-plugin-node-resolve';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
export default {
external: ['aws-sdk'],
globals: {
'aws-sdk': 'AWS',
},
input: 'src/eve-redux/eve-redux-store.js',
output: {
file: 'src/bundle.js',
name: 'EVE',
format: 'iife',
},
watch: {
include: 'src/**',
},
plugins: [
json(),
commonjs({
include: 'node_modules/**',
ignoreGlobal: true,
namedExports: {
'node_modules/inferno-redux/index.js': ['Provider'],
'node_modules/aws-sdk/global.js': ['util'],
},
}),
globals(),
builtins(),
resolve({
preferBuiltins: true,
}),
sourcemaps(),
],
}; Rollup successfully bundles the SDK, however, the browser complains:
which takes us to this line: var memoizedProperty$1 = util_1.memoizedProperty; and var util_1 = util; and /**
* A set of utility methods for use with the AWS SDK.
*
* @!attribute abort
* Return this value from an iterator function {each} or {arrayEach}
* to break out of the iteration.
* @example Breaking out of an iterator function
* AWS.util.each({a: 1, b: 2, c: 3}, function(key, value) {
* if (key == 'b') return AWS.util.abort;
* });
* @see each
* @see arrayEach
* @api private
*/
var util = {//...insert AWS util obj here...} |
I got the same problem running on pure [email protected]. I don't have sure if order of lines should be the problem in this case, but i have:
|
Any update? Facing this issue too. |
Check out Amazon's documentation for using aws-iot-device-sdk-js in the browser. https://github.com/aws/aws-iot-device-sdk-js#browser It's pretty crazy, but you have to manually compile the JS and include it separately via <script>. That compiled JS defines
|
|
How is this still an issue? This makes the library completely unusable for anyone using rollup. I would expect a bug of this magnitude to be fixed quickly but it's been over a year and no work as been done on it. I'm by no means an expert with rollup but I suspect the issue arises from the multitude of circular dependencies. |
Was anyone able to solve: "Uncaught TypeError: Cannot read property 'memoizedProperty' of undefined"? |
Looks like I have to use either webpack or mongo stitch. |
@wikiwang1991 yes, for some reason this issue is not getting solved. I use webpack, it works fine after some tinkering with the configs. |
This issue is not open for more than two years... Stumbled upon this while trying to use amplify together with svelte - which uses rollup. |
Finally found a way: You can use webpack instead of rollup to build the application, then everything works just fine. |
For those who don't want to switch from rollup to webpack, what is the recommended course of action? |
Switch to GCP and start using Firebase instead, unfortunately, I think. 😢 |
Has anyone tried rollup with the SDK v3? https://github.com/aws/aws-sdk-js-v3 cc @chufgard |
For GCP, you can instruct external dependancies to be installed on the host machine using a The following worked for me:
import typescript from '@rollup/plugin-typescript'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import copy from 'rollup-plugin-copy2'
export default {
input: './src/index.ts',
preserveSymlinks: true,
plugins: [
typescript(),
nodeResolve({ preferBuiltins: true }),
commonjs({
namedExports: {}
}),
json(),
copy({
assets: [['./package.unbundled.json', 'package.json']]
})
],
external: ['crypto', 'firebase-admin', 'firebase-functions', '@google-cloud/firestore', 'buffer', '@google-cloud/pubsub', 'iltorb', 'aws-sdk'],
output: {
dir: './lib',
format: 'cjs',
sourcemap: true
}
}
|
I ran into this issue recently and after further investigating found that one of the dependencies I had was importing from |
I found a strange way for 'amazon-cognito-identity-js'
import AmazonCognitoIdentity from 'amazon-cognito-identity-js/dist/amazon-cognito-identity.js';
... |
This issue seems to be resolved in v3. I was encountering it with v2, and it went away when upgrading to v3. |
I am still facing issues with v2. Any solution for v2? |
I'am still getting the same error as @bennypowers and @jordanranz reported. BTW I'm using Builds with
Is there at least a workaround for this issue? |
After a few days of trying to fix this issue, I finally got to a working solution aka workaround. First create a file for the functions you use on your project (in my case it was only S3)
import AWS from 'aws-sdk';
const getS3Object = () => {
return new AWS.S3({ region: 'us-west-2' });
};
window.getS3Object = getS3Object; // Expose getS3Object to window object Then create the webpack config file (install webpack if you don't have it).
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
// Specify the entry point for our app.
entry: [path.join(__dirname, 'aws-s3.js')],
// Specify the output file containing our bundled code.
output: {
path: __dirname,
filename: 'aws-s3.min.js',
},
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false, // omit Licence.txt file generation
}),
],
},
// Enable WebPack to use the 'path' package.
resolve: {
fallback: { path: require.resolve('path-browserify') },
},
}; Add the following script to your
"scripts": {
// ...
"build-bundled": "webpack"
} Then run the following command, this will run the webpack with the configurations we set up on
Include the generated
<html>
<body>
<!-- Add this script tag -->
<script type="module" src="/aws-s3.min.js"></script>
</body>
</html> With that, you should be able to call the aws-sdk functions with the windows object. Before
After
|
it works!!! |
can use CDN import AWS not error |
I was able to get https://github.com/rollup/plugins/tree/master/packages/commonjs#strictrequires |
No, not with aws-sdk v2.1143 + Vite 2.9.9. |
With vite, you can do the same solution using export const updateCommonjsPlugin = (): Plugin => {
const commonJs22 = commonjs({
include: [/node_modules/],
extensions: [".js", ".cjs"],
strictRequires: true,
});
return {
name: "new-common-js",
options(rawOptions) {
const plugins = Array.isArray(rawOptions.plugins)
? [...rawOptions.plugins]
: rawOptions.plugins
? [rawOptions.plugins]
: [];
const index = plugins.findIndex(
(plugin) => plugin && plugin.name === "commonjs"
);
if (index !== -1) {
plugins.splice(index, 1, commonJs22);
}
const nextConfig = { ...rawOptions, plugins };
return commonJs22.options.call(this, nextConfig);
},
};
}; Then in your vite config you can do plugins: [updateCommonjsPlugin()], I think vite is planning on upgrading |
@airjp73 this method got rid of the Are you importing aws as es module or using commonjs |
In my case, I'm not using the html output from vite so that could be why I'm not running into that issue. |
Worked! |
I solved it by adding:
|
Still getting |
Thanks this worked, I have other packages that use it though, like amplify, I ended up with this issue [vite:load-fallback] Could not load aws-sdk/dist/aws-sdk.min.js/clients/mobileanalytics (imported by node_modules/.pnpm/@aws-amplify+analytics@1.4.3/node_modules/@aws-amplify/analytics/lib-esm/Providers/AWSPinpointProvider.js): ENOENT: no such file or directory, open 'aws-sdk/dist/aws-sdk.min.js/clients/mobileanalytics' But solved it by adding a more strict regex resolve: {
alias: [
{
find: /^aws-sdk$/,
replacement: "aws-sdk/dist/aws-sdk.min.js",
},
],
}, |
I was able to circumvent runtime errors using AWS sdk v2 by utilizing an import map in index.html and exporting window.AWS in a shim module.
aws-sdk.js
You will also need to mark aws-sdk as external in build options |
Hello. There are some workarounds available in the text of this issue. Please take a look at those workarounds, or migrate to AWS SDK for JS v3. |
With imports of the type
and rollup.config.js featuring:
rollup -c
produces the output:The text was updated successfully, but these errors were encountered: