The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script
Asked Answered
D

3

7

I Just created a react app. The npm start seems to work fine but npm run build is constantly failing. I need to run npm run build to deploy it on some website.

Already gone through all posts related to this on stackoverflow.com. But didn't found any working solution.

import './App.css';
import 'https://kit.fontawesome.com/a076d05399.js'

import Navbar from './components/navbar';
import Homepage from './components/homepage';
import Skills from './components/Skills';
import Project from './components/project';
import Contact from './components/contact';

Error Message

Failed to compile.

The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script     
Dissertate answered 20/10, 2022 at 16:27 Comment(8)
How did you create the project?Peripheral
I used npx create-react-app <project-name>Dissertate
I guess that's because of this line import 'https://kit.fontawesome.com/a076d05399.js'. Why don't you use font-awesome from npm?Peripheral
I did remove that line. But unfortunately nothing changed!! Is there anything else i can do... its been very long and its not resolving..Dissertate
Do you have more imports like this?Peripheral
will that be a problem too? @import url("https://fonts.googleapis.com/css2?family=Poppins&display=swap");Dissertate
I don't think soPeripheral
finally the process is done!! the command worked... There was one more import font statement just as the same above one. and after removing that build command run successfully... Thank you very much..!!Dissertate
S
4

The problem here was the import statement of an external js file.

import 'https://kit.fontawesome.com/a076d05399.js';

You can add the file in index.html & run build.

<script src="https://kit.fontawesome.com/a076d05399.js"></script>

And yes there's no problem with import statement in css.

@import url("https://cdn.jsdelivr.net/npm/[email protected]/fonts/remixicon.css");
Stabilizer answered 22/11, 2022 at 5:16 Comment(1)
Does this work with TypeScript?Aldric
S
1

In my case, it was failing because using external styles

import "https://unpkg.com/[email protected]/dist/leaflet.css";

Fixed with using via npm: npm i leaflet

import 'leaflet/dist/leaflet.css';

Official docs

Slosberg answered 16/11, 2022 at 22:8 Comment(0)
D
0

To dynamically import ES modules you'll need to change webpack's output type to ESM.

Alternatively you could try ignoring the external import with webpackIgnore.

Domino answered 22/9, 2023 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.