Tag Archives: bug

[Solved] Vite build & Flask Error: Failed to load module script. Strict MIME type checking is enforced

Vite build & Flask Error: Failed to load module script. Strict MIME type checking is enforced


Stack Overflow

questions

I have this HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link
        rel="stylesheet"
        href="../../../static/css/style.css"
        type="text/css" />
    <link
        rel="stylesheet"
        href="../../../static/css/user_header.css"
        type="text/css" />

    <!--suppress HtmlUnknownTarget -->
    <link rel="shortcut icon" href="/favicon.png">

    <script type="module" src="../../../static/js/node_connect.js" ></script>  <-- Error
    <script src="../../../static/lib/jquery.min.js"></script>
    <script src="../../../static/lib/selfserve.js"></script>   

</head>

The problem is node_connect.jsfile. Start the flash web tool locally (Python 3.7.2), and the console will report the following error when opening the page:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain".
Strict MIME type checking is enforced for module scripts per HTML spec.

Check Title:

Content-Type: text/plain; charset=utf-8

However, in production (when starting through gunicorn), it gives:

Content-Type: application/javascript; charset=utf-8

I guess the web server (APACHE) serves them in the production case, but another thing is that when testing other pages of the web tool, they all work and load JavaScript files correctly (even if their content type is text/plain text). However, the difference is that I notice that in the type.

This applies to my situation:

<script src="../../static/js/translator/library/materialize.js"></script>

Or this:

<script type="application/javascript" src="../../static/js/translator/library/materialize.js"></script>

Of course, I tried this for the problematic JavaScript . File and received the following error (which means it is now loaded):

Uncaught SyntaxError: Cannot use import statement outside a module

According to my research, this basically means that I need to set the type to module (but this will make the browser reject .js files).

Who can help me solve this problem?

best answer:

The problem is caused by flash how to guess the content type of each static file
Import mimetypes from flash and call mimeType, encoding = mimetypes guess_type (download_name) this module creates a database of known MIME types from multiple sources and uses it to return MIME types
Linux and MacOS: look at the mimetypes.py files:

knownfiles = [
    "/etc/mime.types",
    "/etc/httpd/mime.types",                    # Mac OS X
    "/etc/httpd/conf/mime.types",               # Apache
    "/etc/apache/mime.types",                   # Apache 1
    "/etc/apache2/mime.types",                  # Apache 2
    "/usr/local/etc/httpd/conf/mime.types",
    "/usr/local/lib/netscape/mime.types",
    "/usr/local/etc/httpd/conf/mime.types",     # Apache 1.2
    "/usr/local/etc/mime.types",                # Apache 1.3
    ]

But in windows, it will look in the registry:

with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
    for subkeyname in enum_types(hkcr):
        try:
            with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                # Only check file extensions
                if not subkeyname.startswith("."):
                    continue
                # raises OSError if no 'Content Type' value
                mimetype, datatype = _winreg.QueryValueEx(
                    subkey, 'Content Type')
                if datatype != _winreg.REG_SZ:
                    continue
                self.add_type(mimetype, subkeyname, strict)

So to solve the problem, flask thinks JS file is actually a problem of text/plain , just open regedit and adjust this registry key to application/javaScript .

solutions for vite:

Find the registry value, double-click content type to change it to Application/JavaScript , and then restart the computer

if not, please see if your suffix is simple .js, if it is .1242342.js , must be changed to pure .JS suffix can take effect

In order to completely eradicate the disadvantages of modifying files, we can change the configuration file of vite , and modify the name of the output JS file by using the custom packaging option rollupOptions.

Reference: vite2 how to set the file name after packaging

Other configuration items of vite.config.js are shown on the official website. Click here to view more configuration items on the official website.

[Solved] Opencv Call yolov3 Error: IndexError: invalid index to scalar variable

Call the weight file of yolov3 with OpenCV to obtain the names of the three scale output layers and report an error

ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]

Error reporting
indexerror: invalid index to scalar variable

This code was a few years ago. It may be a problem with the version. Now it will report an error

Solution:
Remove [0] and modify as below:

ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]

[Solved] RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dim

Error Messages:
tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0

Error Reason:
Dimensional information mismatch

Original Code:

image = Image.open(image_path)

After modification:

image = Image.open(image_path).convert('RGB')

[Solved] NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL ,unhandled cuda error, NCCLversion 2.7.8

The method used in this paper

The versions of pytorch, cudatoolkit and CUDA driver should be consistent

Problem description

When training the stylegan3 model with multi GPU:

python train.py --outdir=training-runs --cfg=stylegan3-r \
--data=datastes/your_data.zip \
--cfg=stylegan3-r --gpus=4 --batch=32 --gamma=8 --kimg=1800 --snap=50  --tick=2  

Error Messages:

torch.multiprocessing.spawn.ProcessRaisedException:
……
RuntimeError: NCCL error in: /opt/conda/conda-bld/pytorch_1631630841592/work/torch/lib/c10d/ProcessGroupNCCL.cpp:911, unhandled cuda error, NCCL version 2.7.8
ncclUnhandledCudaError: Call to CUDA function failed.

Local Environment
4xTeslaV100 graphics card drivers and CUDA version 11.0

stylegan3 Default Environment

Solution:
Go to the pytorch official website and search the corresponding version of  Cudatookit

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

Tried Method:

Method 1: install nccl (this article is useless)

Method 2: the versions of pytorch, CUDA toolkit and CUDA driver are the same

https://github.com/ultralytics/yolov5/issues/4530

How to Solve screenfull plug-in Error (Version Issues)

We can use handwriting directly to realize the full screen function, but it is very convenient to use the screenfull plug-in to deal with the problem of full screen, but there is a bug in normal use today

Install NPM package NPM i screenfull ,the default is to import the latest version

Import Import screenfull from 'screenfull' to use

You can use the full screen function nomarlly screenfull.toggle()

At this time, I reported an error to me

when the page was blank and could not be loaded, I went to the Internet to find several articles that said the version was too high and needed to reduce the version of the package plug-in. I tried many times and still reported an error

Solution:

It’s really necessary to reduce the version. I’ve reduced it to [email protected] Version, then why do you report an error?I found that the imported path is screenfull under the module directory, but there is no corresponding index.js file

so we have to change the import path import ScreenFull from 'screenfull/dist/screenfull', the page will be displayed normally and the full screen function will be normal

Using Post no Body Error: socket hang up [How to Solve]

Project scenario:

Due to environmental problems, the server is only allowed to use the post and get methods to call the interface. The delete interface written using the post method can be called locally, but an error is reported in the server.


Problem description

Use the post method for logical deletion and error reporting, and use @pathvariable to obtain the front-end transmission parameters:

@PostMapping("/delete/{userGroupIds}")
public ResponseBean<Object> deleteUserGroup(@PathVariable("userGroupIds") String userGroupIds){
    return userGroupService.deleteUserGroup(userGroupIds);
}

When using postman to call the server interface, the following error messages appear:

The front-end page calls the interface and reports the following error, cross domain:


Cause analysis:

The post method needs to use @Rquestbody to obtain parameters. This problem occurs when null is passed. The specific details were not clarified.


Solution:

Change the @pathvariable method to @rquestbody .

@PostMapping("/delete")
public ResponseBean<Object> deleteUserGroup(@RequestBody UserGroupIdDTO userGroupIds){
    return userGroupService.deleteUserGroup(userGroupIds);
}

The parameters in UserGroupIdDTO are as follows:

@Data
public class UserGroupIdDTO {
    private String userGroupId;
}

[Solved] main.py: error: the following arguments are required:

Error “main. Py: error: the following arguments are required:”

1. Check the error message first

As shown in the figure below,
main.py: error: the following arguments are required: -- task, -- dataset, -- param
generally speaking, the three parameters I set task, dataset, param have problems
find the place where I set the parameters and find that these three parameters have the attribute required=True

parser.add_argument("--task", default='uabsa', type=str, required=True,
                    help="The name of the task, selected from: [uabsa, aste, tasd, aope]")
parser.add_argument("--dataset", default='rest14', type=str, required=True,
                    help="The name of the dataset, selected from: [laptop14, rest14, rest15, rest16]")
parser.add_argument("--model_name_or_path", default='t5-base', type=str,
                    help="Path to pre-trained model or shortcut name")
parser.add_argument("--paradigm", default='annotation', type=str, required=True,
                    help="The way to construct target sentence, selected from: [annotation, extraction]")

2. Solutions

Method 1:

1.Run–> Edit Configurations

2. main.py (corresponding error report file), fill in the corresponding -- task "uabsa" -- dataset "rest14" -- param "Annotation", here are the error report parameters and the corresponding default values
for example, here — the default of task is “uabsa”, note: it is double quotation marks instead of single quotation marks, and there may be problems with single quotation marks Click OK after filling in.

Method 2: if method 1 and other methods do not work (simple, but not recommended)

Find the set generation of three variables and delete required=True in the code.
initially

parser.add_argument("--task", default='uabsa', type=str, required=True,
                    help="The name of the task, selected from: [uabsa, aste, tasd, aope]")
parser.add_argument("--dataset", default='rest14', type=str, required=True,
                    help="The name of the dataset, selected from: [laptop14, rest14, rest15, rest16]")
parser.add_argument("--model_name_or_path", default='t5-base', type=str,
                    help="Path to pre-trained model or shortcut name")
parser.add_argument("--paradigm", default='annotation', type=str, required=True,
                    help="The way to construct target sentence, selected from: [annotation, extraction]")

After deletion

parser.add_argument("--task", default='uabsa', type=str,
                    help="The name of the task, selected from: [uabsa, aste, tasd, aope]")
parser.add_argument("--dataset", default='rest14', type=str, 
                    help="The name of the dataset, selected from: [laptop14, rest14, rest15, rest16]")
parser.add_argument("--model_name_or_path", default='t5-base', type=str,
                    help="Path to pre-trained model or shortcut name")
parser.add_argument("--paradigm", default='annotation', type=str,
                    help="The way to construct target sentence, selected from: [annotation, extraction]")

[Solved] Heroku Error: Web process failed to bind to $PORT within 60 seconds of launch

Error description

If the set port number is less than 1000, an error will be reported, and there is no permission

2022-03-29T10:23:16.651636+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-29T10:23:28.994173+00:00 heroku[web.1]: Starting process with command `python /code/server3.py`
2022-03-29T10:23:30.091143+00:00 app[web.1]: Traceback (most recent call last):
2022-03-29T10:23:30.091204+00:00 app[web.1]: File "/code/server3.py", line 247, in <module>
2022-03-29T10:23:30.091205+00:00 app[web.1]: serverSocket.bind(("127.0.0.1", serverPort))
2022-03-29T10:23:30.091208+00:00 app[web.1]: PermissionError: [Errno 13] Permission denied
2022-03-29T10:23:30.234919+00:00 heroku[web.1]: Process exited with status 1
2022-03-29T10:23:30.279569+00:00 heroku[web.1]: State changed from starting to crashed

If you set the port number to 8080, you will not be connected within 60 seconds

2022-03-29T10:53:34.400924+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-29T10:53:49.432473+00:00 heroku[web.1]: Starting process with command `python /code/server3.py`
2022-03-29T10:53:33.432308+00:00 app[api]: Release v9 created by user ***@icloud.com
2022-03-29T10:53:33.432308+00:00 app[api]: Deployed web (350d1bd5740a) by user ***@icloud.com
2022-03-29T10:54:49.500818+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-03-29T10:54:49.587777+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-03-29T10:54:49.800462+00:00 heroku[web.1]: Process exited with status 137

If the port number in the environment variable is referenced dynamically, the acquisition fails

2022-03-29T11:12:03.984493+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-29T11:12:19.984320+00:00 heroku[web.1]: Starting process with command `python /code/server3.py`
2022-03-29T11:12:21.706887+00:00 heroku[web.1]: Process exited with status 1
2022-03-29T11:12:21.536737+00:00 app[web.1]: Traceback (most recent call last):
2022-03-29T11:12:21.536756+00:00 app[web.1]: File "/code/server3.py", line 248, in <module>
2022-03-29T11:12:21.536757+00:00 app[web.1]: serverSocket.bind(("0.0.0.0", serverPort))
2022-03-29T11:12:21.536757+00:00 app[web.1]: TypeError: an integer is required (got type NoneType)
2022-03-29T11:12:21.769096+00:00 heroku[web.1]: State changed from starting to crashed

No matter the local address is not written,
ServerSocket Bind ((“”, serverport))
or 127.0.0.1
ServerSocket Bind ((“127.0.0.1”, serverport))
or write 0.0.0
ServerSocket Bind ((“0.0.0.0”, serverport))
doesn’t work

 

Solution (Python Project):

Dynamic binding port number is required

To write this in dockerfile, pass in $post

#Base image based on
FROM python:3.4

#code added to code folder
ADD . /pythonProject /code

# Set the code folder to be the working directory
WORKDIR /code

# Install support
#RUN pip install -r requirements.txt

CMD python /code/server3.py $PORT

Python file writing format,  obtain through parameters in server.py

serverPort = int(sys.argv[1])

The complete structure is as follows

if __name__ == '__main__':
    serverSocket = socket(AF_INET, SOCK_STREAM)
    serverPort = int(sys.argv[1])
    serverSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    serverSocket.bind(("", serverPort))

    serverSocket.listen(5)
    print('The server is running')
    # Main web server loop. It simply accepts TCP connections, and get the request processed in seperate threads.
    while True:
        # Set up a new connection from the client
        connectionSocket, addr = serverSocket.accept()
        # Clients timeout after 60 seconds of inactivity and must reconnect.
        connectionSocket.settimeout(600)
        # start new thread to handle incoming request
        _thread.start_new_thread(process, (connectionSocket,))

Solution (Nodejs Project):

// production
config.port = process.env.PORT

app.listen(config.port, () => {
  logger.info('Listening on port %d', config.port);
});

or

.listen(process.env.PORT || 5000)

or

production: {
    server: {
        host: '0.0.0.0',
        port: process.env.PORT
    }
}

[Solved] Nacos Cluster startup error: error=‘Cannot allocate memory‘ (errno=12)

Problem discovery

1. Start one of the Nacos clusters

2. Query the number of starts through the number of starts in the cluster command

ps -ef|grep nacos|grep -v grep|wc -l

This is the second startup. One has been started before, so the problem comes. Why is it still one after the second startup

3. Use the tail-f command to read the contents of the file loop, monitor the growth of the file and find out the reason

tail -f 文件路径   #The file path is given after the start command

Normal start

Second startup error

From the Nacos startup log information, we can see that the memory is insufficient

4. Check the memory usage through the free -h command

There is only 70m of available memory left

5. By viewing startup.sh file to view the JVM startup command

– xms2g represents 2G of initially allocated memory
– xmx2g represents the maximum value of JVM memory
– xmn1g represents 1g of Cenozoic memory;

Solution:

1. Increase system memory

2. Modify the startup parameters of the JVM in the startup script and reduce the memory allocated to the JVM

Allocate according to your current usage mode and the memory of your virtual machine

After modification, it is started successfully

[Solved] Syntax Error: Error: ENOENT: no such file or directory, scandir ‘D:\LeStoreD

Syntax Error: Error: ENOENT: no such file or directory, scandir ‘D:\LeStoreD

Solution: execute the following command

npm rebuild node-sass

PS D:\LeStoreDownload\CinemaBookingSystem-master\panda-user> npm install
up to date in 21.517s

62 packages are looking for funding
  run `npm fund` for details

PS D:\LeStoreDownload\CinemaBookingSystem-master\panda-user> npm rebuild node-sass

> [email protected] install D:\LeStoreDownload\CinemaBookingSystem-master\panda-user\node_modules\node-sass
> node scripts/install.js

Cached binary found at C:\Users\29395\AppData\Roaming\npm-cache\node-sass\4.14.1\win32-x64-83_binding.node

> [email protected] postinstall D:\LeStoreDownload\CinemaBookingSystem-master\panda-user\node_modules\node-sass
> node scripts/build.js

Binary found at D:\LeStoreDownload\CinemaBookingSystem-master\panda-user\node_modules\node-sass\vendor\win32-x64-83\binding.node
Testing binary
Binary is fine
[email protected] D:\LeStoreDownload\CinemaBookingSystem-master\panda-user\node_modules\node-sass

How to Solve Azkaban error (Reasons & Solutions)

Error 1: azkaban job Preparing
Solution:
modify the configuration of web-server conf/azkaban.properties
# execute host filter configuration, remove MinimumFreeMemory
# MinimumFreeMemory filter will check if the executor host will have more than 6G of free memory, if less than 6G, the web-server will not send the task to that host
azkaban.executorselector.filters=StaticRemainingFlowSize,CpuStatus

Error 2: When the job is running,azkaban web Error: Free memory amount minus Xmx (2836204 – 0 kb) is less than low mem threshold (3145728 kb), memory request declined

Solution:
[root@qphone02 executor]# vi ./plugins/jobtypes/commonprivate.properties
# set execute-as-user
execute.as.user=false
memCheck.enabled=false  # add memory check is off, otherwise it will report error: less than 3G