In remix.js I, want to import createEmotionServer from #emotion/server/create-instance. It is giving me, error. Is there is something wrong in this code.
The import statement is this:
import createEmotionServer from "#emotion/server/create-instance";
It is just an import statement. But in remix it is showing the error
Error: Cannot find module '#emotion/server/create-instance'
Is there is any other module path from which I need to import it ?
Guys I am still new to Node.js and facing a problem during importing a third-party module. The module name is #azure/storage-blob and my package.json file is using "type": "module" setting.
When I try to import this module with the following syntax. I am getting an error.
import { BlobServiceClient } from "#azure/storage-blob";
SyntaxError: The requested module '#azure/storage-blob' does not provide an export named 'BlobServiceClient'
at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:107:20)
at async Loader.import (internal/modules/esm/loader.js:179:24)
But with this setting, this project is working fine on my other machine and I still don't understand it.
When I use this syntax instead of directly import the error goes away.
import AzureStorageBlob from "#azure/storage-blob";
const { BlobServiceClient } = AzureStorageBlob;
Could you please help me to understand this issue?
I am using vue-cli and workbox-webpack-plugin injectMode
new InjectManifest({
swSrc: './src/sw.ts',
swDest: 'sw.js',
}),
in sw.ts, I try to import other file
import { precacheAndRoute } from 'workbox-precaching'
import { registerRoute } from 'workbox-routing'
import { WorkboxPlugin, setCacheNameDetails, RouteHandler } from 'workbox-core'
import { CacheableResponsePlugin } from 'workbox-cacheable-response'
import { ExpirationPlugin } from 'workbox-expiration'
import Strategies, { CacheFirst, StaleWhileRevalidate } from 'workbox-strategies'
// import other file
import { CustomMessage, MessageType, MESSAGE_META, SWRouting } from './utils/registerSW'
but when building APP, it will fail,
error: js/chunk-2d213953.a6b52dae.js from Terser
Unexpected token: punc (:) [js/chunk-2d213953.a6b52dae.js:3,12]
when I remove this import statment, building works well.
So, Could I import other files ? How ?
Generally speaking, what you're trying to do should work. The InjectManifest plugin will kick off a webpack child compilation for the your swSrc file, and will inherit whatever plugins and config you have set up for your main, parent compilation. It should be able to bundle ES modules into a final service worker.
It sounds like there's something specific in one of those ./utils/registerSW imports that is causing Terser to be unable to parse the bundled code, though. I would recommend starting by just importing a very small, no-op function from ./utils/registerSW, and confirm that that works. Then try importing each of those functions from ./utils/registerSW one at a time until you find the one that's causing issues, and check the original source code to see what might be triggering it.
It's possible that the child compilation kicked off by InjectManifest is misconfigured, and perhaps that's due to a bug that needs to be fixed, but I would start with those debugging steps first.
In my node.js (express.js) project, I try to wrap axios to create a HttpClient like this:
import axios from 'axios';
const httpClient = axios.create({ baseURL: 'http://locahost:3003' });
...
export const httpClient = {
...
};
When I run it, I get error SyntaxError: Cannot use import statement outside a module which complains the line import axios from 'axios'. How can I get rid of this error? (I come from React-native world, I used the same thing in React-Native, it is fine)
The issue is by default express uses CJS format of importing as you might have seen const axios = require("axios").
What you are trying to do is an ESM format of import which is not understood by the JS as natively. To work import statements you can either add the following property to your package.json file - "type": "module" or you can use ".mjs" extension instead of default ".js" extension.
Hope this link helps further.
I have a very simple Rollup plugin I made. This works great if I run with the following import (using local relative)...
import { SassShadow } from '../../../rollup-sass-shadow/index.mjs';
But when I try to run with the npm version like this...
import { SassShadow } from '#jrg/rollup-sass-shadow';
I get...
[!] TypeError: defaultLoader is not a function
TypeError: defaultLoader is not a function
How do I get this to work?
The only way I could get this to work was to use the default export instead of the named export. So instead of...
export class SassShadow{...}
import { SassShadow } from '#jrg/rollup-sass-shadow';
It needed to be...
class SassShadow{...}
export default SassShadow
import SassShadow from '#jrg/rollup-sass-shadow'