swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

Can’t enable dynamic imports #16

Closed sabberworm closed 3 years ago

sabberworm commented 3 years ago

I have configured swc-loader as follows:

{
    test: /\.tsx?$/,
    exclude: /\/node_modules\//,
    use: [
        {
            loader: 'swc-loader',
            options: {
                jsc: {
                    externalHelpers: true,
                    parser: {
                        dynamicImport: true,
                        syntax: 'typescript',
                    },
                    transform: {
                        react: {
                            pragma: 'SnabbdomPragma.createElement',
                        },
                    },
                },
            },
        },
    ],
},

Notice the dynamicImport: true. Yet running webpack yields an error where I use my dynamic import:

error: import(...) expressions requires `jsc.parser.dynamicImport` to be true
  --> /«redacted»/components.ts:21:17
   |
21 |         return (await import(/* webpackChunkName: "accordion" */ 'components/accordion/Tc.Module.Accordion')).default;
   |                       ^^^^^^

Any other location I need to configure dynamicImport: true?

kdy1 commented 3 years ago

Can you try changing the order of dynamicImport: true, and syntax: 'typescript'? `

sabberworm commented 3 years ago

I tried and it worked. Now I reverted the change and it still works. In any case, I did have some other problems in my config which I eventually ironed out so maybe they caused this. In that case it’d simply be a duplicate of #12…