You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

跟随Udemy Jonas《Node.js, Express, MongoDB & More: The Complete Bootcamp 2022》课程时遇到Mapbox加载失败与Axios被CSP阻止的技术问题求助

Fixing Mapbox & Axios Issues in Jonas' Node.js Bootcamp

Hey there! Let's tackle these two frustrating issues one by one—they're both tied to modern browser security policies, which can be a bit finicky but totally solvable.

1. Mapbox Not Loading (ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep)

What's going on?

This error stems from the Cross-Origin Embedder Policy (COEP). Your browser is blocking the old Mapbox GL JS v0.54.0 resources because they don’t include the required cross-origin headers, while your page likely has COEP set to require-corp (either via a server response header or meta tag).

Fixes to try:

  • Upgrade Mapbox GL JS to the latest version: Older versions like v0.54.0 don’t support modern cross-origin policies. Swap out your Mapbox links with the latest stable release (as of now, v2.15.0):
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css' rel='stylesheet' />
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js'></script>
    
    Newer Mapbox resources include proper cross-origin headers, so this should resolve the COEP conflict immediately.
  • Relax COEP settings (last resort): If you must stick with the old version, you can weaken your COEP policy by removing require-corp or adding unsafe-none. Note that this reduces page security, so only do this if upgrading isn’t an option.

2. Axios Blocked by Content Security Policy (CSP)

What's going on?

Your page’s CSP is set to only allow scripts from your own domain ('self') and blob URLs. Loading Axios from cdnjs violates this rule because it’s an external domain not listed in the script-src directive.

Fixes to try:

  • Update your CSP to allow cdnjs: Add https://cdnjs.cloudflare.com to your script-src directive. If using a meta tag for CSP, modify it like this:
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' blob: https://cdnjs.cloudflare.com;">
    
    If your CSP is set via a server response header (e.g., in Express), update the Content-Security-Policy header value to include the cdnjs URL.
  • Host Axios locally: Download the Axios minified file, place it in your project’s static assets folder (like public/js/), then reference it locally:
    <script src='/js/axios.min.js'></script>
    
    This loads the script from your own domain, which complies with the 'self' rule.
  • Install Axios via npm (best practice): If you’re using npm in your project, install Axios directly:
    npm install axios
    
    Then import it in your JavaScript files instead of using a CDN script tag:
    import axios from 'axios';
    
    This keeps dependencies managed and avoids CSP issues entirely.

内容的提问来源于stack exchange,提问作者Nikhil Patil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 00:57:35