// vscode配置一个launch.json
{"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}", // 当前文件
"outFiles": [ "${workspaceFolder}/dist/cmd/*.js"], // 核心配置
"runtimeArgs": ["--experimental-modules"] //核心配置是这一句
}]}
//最终的版本很精简
{
version: '0.2.0',
configurations: [
{
type: 'node',
request: 'launch',
name: 'Launch Program',
skipFiles: ['<node_internals>/**'],
program: '${file}',
outFiles: [
'${workspaceFolder}/dist/api/*.js'
]
}
]
}
//解释
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
// "runtimeArgs": ["--experimental-modules"], //支持module核心配置是这一句, 但是现在也不需要了.
"program": "${file}", //这个好, 这个是当前文件
"skipFiles": [
"<node_internals>/**"
],
// "sourceMaps": true, //这个没必要, 本来默认就是true
//"stopOnEntry": true, //这个并不是必须的
//smartStep": false, //也不是必须的
//下面三行是关键内容
"outFiles": [ //这个字段很关键, 没有这个就不能调试coffee, 这是说到哪里去搜索
"${workspaceFolder}/dist/api/*.js"
//"这里是webpack输出的js的地址", 配置成下面这样也可以, 搜索目录会多
//"${workspaceFolder}/**/*.js"
]
}
]
}
# package.json
yarn add webpack-glob --dev
"devDependencies": {
"webpack-glob": "^2.0.2",
},
# webpack配置文件
glob = require "glob"
# ...
entry:{
# bin: './src/test.cs' #直接指定测试文件, 是比较柔软的做法
# 这个要指明目录,web专属内容cmd是编译不过去的, 比如css module
(glob.sync('./src/**/**.cs').reduce (obj, el)->
obj[path.parse(el).name] = el
obj
,{})...
}
# package.json的module设置是没用的
# 不止没用, 还很可能捣乱, 引起webpack不正常, 因此最好删除掉, package.json是纯正的json, 不能有注释
"type": "module",
# 第一个错
/usr/local/bin/node ./src/mcktools/test.js
Could not read source map for coffeescript: Invalid URL: coffeescript
(node:27427) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Process exited with code 1
# 第二个错
Unknown file extension ".cs"
# 这个错误就是 package.json的 'type':'domule'引起的
# 报错
node src/mcktools/test.cs # 下面是报错:
1 ↵
(node:3383) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/machangkun/git/work/weixin/天眼/tianyanbackstage/src/mcktools/test.cs:5
import router from './router.cs'
^^^^^^
SyntaxError: Cannot use import statement outside a module
# 改package.json 添加type:madule
# 后来证明这个是错误做法
# 第二个错
# 这个错误就是 package.json的 'type':'domule'引起的
node src/mcktools/test.cs # 下面是报错: 1 ↵
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".cs" for /Users/machangkun/git/work/weixin/天眼/tianyanbackstage/src/mcktools/test.cs
# 这样还是一样的
node --inspect src/mcktools/test.cs 1 ↵
Debugger listening on ws://127.0.0.1:9229/e764f1a4-2c47-4ea1-8bc0-481266a0f31e
For help, see: https://nodejs.org/en/docs/inspector
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".cs" for /Users/machangkun/git/work/weixin/天眼/tianyanbackstage/src/mcktools/test.cs
# 换这一句, 是被废弃的
coffee --nodejs debug src/mcktools/test.cs
# 换这一句
coffee --nodejs inspect src/mcktools/test.cs # 反馈正常了一点, 但是依旧不对劲
< Debugger listening on ws://127.0.0.1:9229/04eda494-505a-4cba-8f71-6bb4a6825143
< For help, see: https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in /usr/local/lib/node_modules/coffeescript/bin/coffee:4
2
3 try {
> 4 new Function('var {a} = {a: 1}')();
5 } catch (error) {
6 console.error('Your JavaScript runtime does not support some features used by the coffee command. Please use Node 6 or later.');