cloudinary / cloudinary-svelte

Cloudinary components library for Svelte
MIT License
17 stars 3 forks source link

Type error on image component #9

Closed CobyPear closed 3 years ago

CobyPear commented 3 years ago

Bug report for Cloudinary Svelte SDK

Before proceeding, please update to latest version and test if the issue persists

Describe the bug in a sentence or two.

Uncaught type error on Image component. …

Issue Type (Can be multiple)

[ ] Build - Can’t install or import the SDK [ ] Babel - Babel errors or cross browser issues [ ] UI/Performance - Display or performance issues [x] Behaviour - Functions aren’t working as expected (Such as generate URL) [ ] Documentation - Inconsistency between the docs and behaviour [ ] Other (Specify)

Steps to reproduce

… if applicable

  1. Install @cloudinary/svelte npm package
  2. import { Image } and implement

ER: Image is displayed on page from Cloudinary server AR: Type error, Image is not a constructor:

index.umd.js:1 Uncaught TypeError: index_umd.Image is not a constructor
    at create_if_block$3 (index.umd.js:1)
    at create_fragment$6 (Contact.svelte:19)
    at init (index.mjs:1806)
    at new Contact (Contact.svelte:7)
    at create_fragment$5 (Pricing.svelte:40)
    at init (index.mjs:1806)
    at new Pricing (Pricing.svelte:9)
    at create_fragment$4 (Pricing.svelte:9)
    at init (index.mjs:1806)
    at new Home (Home.svelte:9)

Error screenshots

… if applicable

Browsers (if issue relates to UI, else ignore)

[ ] Chrome [ ] Firefox [ ] Safari [ ] Other (Specify) [ ] All

Versions and Libraries (fill in the version numbers)

Svelte Cloudinary SDK - 1.0.0-beta.11 Svelte - 3.0.0 Babel - 0.0.0 Rollup/Other - 2.3.4 Node - 16.8.2 NPM - 7.21.0

Config Files (Please paste the following files if possible)

package.json

{
  "name": "svelte-app",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public --no-clear -s",
    "check": "svelte-check --tsconfig ./tsconfig.json"
  },
  "devDependencies": {
    "@rollup/plugin-commonjs": "^17.0.0",
    "@rollup/plugin-node-resolve": "^11.0.0",
    "@rollup/plugin-typescript": "^8.0.0",
    "@tsconfig/svelte": "^2.0.0",
    "rollup": "^2.3.4",
    "rollup-plugin-css-only": "^3.1.0",
    "rollup-plugin-livereload": "^2.0.0",
    "rollup-plugin-svelte": "^7.0.0",
    "rollup-plugin-terser": "^7.0.0",
    "svelte": "^3.0.0",
    "svelte-check": "^2.0.0",
    "svelte-preprocess": "^4.0.0",
    "tslib": "^2.0.0",
    "typescript": "4.3.5"
  },
  "dependencies": {
    "@cloudinary/svelte": "^1.0.0-beta.11",
    "sirv-cli": "^1.0.0",
    "svelte-routing": "^1.6.0"
  }
}

babel.config.js rollup.config.js

import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
import css from 'rollup-plugin-css-only';

const production = !process.env.ROLLUP_WATCH;

function serve() {
    let server;

    function toExit() {
        if (server) server.kill(0);
    }

    return {
        writeBundle() {
            if (server) return;
            server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
                stdio: ['ignore', 'inherit', 'inherit'],
                shell: true
            });

            process.on('SIGTERM', toExit);
            process.on('exit', toExit);
        }
    };
}

export default {
    input: 'src/main.ts',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        svelte({
            preprocess: sveltePreprocess({ sourceMap: !production }),
            compilerOptions: {
                // enable run-time checks when not in production
                dev: !production,
                hydratable: true
            }
        }),
        // we'll extract any component CSS out into
        // a separate file - better for performance
        css({ output: 'bundle.css' }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),
        typescript({
            sourceMap: !production,
            inlineSources: !production
        }),

        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};

Repository

If possible, please provide a link to a reproducible repository that showcases the problem I can provide this if needed.

ghost commented 3 years ago

Hi @CobyPear ! The repo for the new (Beta) version of @cloudinary/svelte has moved to https://github.com/cloudinary/frontend-frameworks Can you please post your issue there? Thanks

eyalktCloudinary commented 3 years ago

@CobyPear As @maoznir mentioned, you can find the latest Svelte SDK in - https://github.com/cloudinary/frontend-frameworks/tree/main/frameworks/svelte The issue doesn't get reproduced when following the example listed on that repository (here is a codesandbox example). Cheers!

CobyPear commented 3 years ago

@eyalktCloudinary Thank you, I realized this morning that I missed a step! Appreciate it.